Skip to content

Commit

Permalink
Add -noinapp option to disable Steam "in game" visibility (fix #4314)
Browse files Browse the repository at this point in the history
Some minor changes in this commit includes the usage of
std::unique_ptr for the Pimpl-idiom in steam::SteamAPI class and
renaming the SteamAPI::initialized() to SteamAPI::isInitialized() to
avoid confusion reading the code.

Forum post:
https://steamcommunity.com/app/431730/discussions/2/7260435303111061192/
  • Loading branch information
dacap committed Feb 21, 2024
1 parent 5337a72 commit 0d5075f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,10 @@ if(ENABLE_UPDATER)
endif()

if(ENABLE_STEAM)
add_definitions(-DENABLE_STEAM)
# We need the ENABLE_STEAM flag in main module too so AppOptions are
# equal in both modules, app-lib and main (that's why this flag is
# marked as PUBLIC).
target_compile_definitions(app-lib PUBLIC -DENABLE_STEAM)
target_link_libraries(app-lib steam-lib)
endif()

Expand Down
22 changes: 18 additions & 4 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -328,6 +328,11 @@ int App::initialize(const AppOptions& options)
app_configure_drm();
#endif

#ifdef ENABLE_STEAM
if (options.noInApp())
m_inAppSteam = false;
#endif

// Load modules
m_modules = std::make_unique<Modules>(createLogInDesktop, preferences());
m_legacy = std::make_unique<LegacyModules>(isGui() ? REQUIRE_INTERFACE: 0);
Expand Down Expand Up @@ -510,9 +515,18 @@ void App::run()

// Initialize Steam API
#ifdef ENABLE_STEAM
steam::SteamAPI steam;
if (steam.initialized())
os::instance()->activateApp();
std::unique_ptr<steam::SteamAPI> steam;
if (m_inAppSteam) {
steam = std::make_unique<steam::SteamAPI>();
if (steam->isInitialized())
os::instance()->activateApp();
}
else {
// We tried to load the Steam SDK without calling
// SteamAPI_InitSafe() to check if we could run the program
// without "in game" indication but still capturing screenshots
// on Steam, and that wasn't the case.
}
#endif

#if defined(_DEBUG) || defined(ENABLE_DEVMODE)
Expand Down
5 changes: 4 additions & 1 deletion src/app/app.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -142,6 +142,9 @@ namespace app {
std::unique_ptr<LegacyModules> m_legacy;
bool m_isGui;
bool m_isShell;
#ifdef ENABLE_STEAM
bool m_inAppSteam = true;
#endif
std::unique_ptr<MainWindow> m_mainWindow;
base::paths m_files;
#ifdef ENABLE_UI
Expand Down
12 changes: 11 additions & 1 deletion src/app/cli/app_options.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -79,6 +79,9 @@ AppOptions::AppOptions(int argc, const char* argv[])
, m_exportTileset(m_po.add("export-tileset").description("Export only tilesets from visible tilemap layers"))
, m_verbose(m_po.add("verbose").mnemonic('v').description("Explain what is being done"))
, m_debug(m_po.add("debug").description("Extreme verbose mode and\ncopy log to desktop"))
#ifdef ENABLE_STEAM
, m_noInApp(m_po.add("noinapp").description("Disable \"in game\" visibility on Steam\nDoesn't count playtime"))
#endif
#ifdef _WIN32
, m_disableWintab(m_po.add("disable-wintab").description("Don't load wintab32.dll library"))
#endif
Expand Down Expand Up @@ -121,6 +124,13 @@ bool AppOptions::hasExporterParams() const
m_po.enabled(m_sheet);
}

#ifdef ENABLE_STEAM
bool AppOptions::noInApp() const
{
return m_po.enabled(m_noInApp);
}
#endif

#ifdef _WIN32
bool AppOptions::disableWintab() const
{
Expand Down
8 changes: 7 additions & 1 deletion src/app/cli/app_options.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -95,6 +95,9 @@ class AppOptions {
const Option& exportTileset() const { return m_exportTileset; }

bool hasExporterParams() const;
#ifdef ENABLE_STEAM
bool noInApp() const;
#endif
#ifdef _WIN32
bool disableWintab() const;
#endif
Expand Down Expand Up @@ -166,6 +169,9 @@ class AppOptions {

Option& m_verbose;
Option& m_debug;
#ifdef ENABLE_STEAM
Option& m_noInApp;
#endif
#ifdef _WIN32
Option& m_disableWintab;
#endif
Expand Down
10 changes: 4 additions & 6 deletions src/steam/steam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class SteamAPI::Impl {
unloadLib();
}

bool initialized() const {
bool isInitialized() const {
return m_initialized;
}

Expand Down Expand Up @@ -239,23 +239,21 @@ SteamAPI* SteamAPI::instance()
}

SteamAPI::SteamAPI()
: m_impl(new Impl)
: m_impl(std::make_unique<Impl>())
{
ASSERT(g_instance == nullptr);
g_instance = this;
}

SteamAPI::~SteamAPI()
{
delete m_impl;

ASSERT(g_instance == this);
g_instance = nullptr;
}

bool SteamAPI::initialized() const
bool SteamAPI::isInitialized() const
{
return m_impl->initialized();
return m_impl->isInitialized();
}

void SteamAPI::runCallbacks()
Expand Down
8 changes: 5 additions & 3 deletions src/steam/steam.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite Steam Wrapper
// Copyright (c) 2020 Igara Studio S.A.
// Copyright (c) 2020-2024 Igara Studio S.A.
// Copyright (c) 2016 David Capello
//
// This file is released under the terms of the MIT license.
Expand All @@ -9,6 +9,8 @@
#define STEAM_STEAM_H_INCLUDED
#pragma once

#include <memory>

namespace steam {

class SteamAPI {
Expand All @@ -18,7 +20,7 @@ class SteamAPI {
SteamAPI();
~SteamAPI();

bool initialized() const;
bool isInitialized() const;
void runCallbacks();

bool writeScreenshot(void* rgbBuffer,
Expand All @@ -27,7 +29,7 @@ class SteamAPI {

private:
class Impl;
Impl* m_impl;
std::unique_ptr<Impl> m_impl;
};

} // namespace steam
Expand Down

0 comments on commit 0d5075f

Please sign in to comment.