Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion include/element/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Settings : public juce::ApplicationProperties,
static const char* oscHostPortKey;
static const char* oscHostEnabledKey;
static const char* systrayKey;
static const char* startHiddenKey;
static const char* midiOutLatencyKey;
static const char* desktopScaleKey;
static const char* mainContentTypeKey;
Expand All @@ -55,7 +56,11 @@ class Settings : public juce::ApplicationProperties,
static const char* transportStartStopContinue;

bool getBool (std::string_view key, bool fallback = false) const noexcept;
int getInt (std::string_view key, int fallback = 0) const noexcept;
double getDouble (std::string_view key, double fallback = 0.0) const noexcept;
juce::String getString (std::string_view key, const juce::String& fallback = {}) const;

/** Stores a value. Does nothing if the stored value is already equal. */
void set (std::string_view key, const juce::var& value);

std::unique_ptr<juce::XmlElement> getLastGraph() const;
Expand Down Expand Up @@ -89,7 +94,7 @@ class Settings : public juce::ApplicationProperties,
void setPluginWindowsOnTop (const bool);

/** True if the user should be prompted to save when exiting the app */
bool askToSaveSession();
bool askToSaveSession() const;
void setAskToSaveSession (const bool);

const juce::File getDefaultNewSessionFile() const;
Expand Down Expand Up @@ -118,6 +123,11 @@ class Settings : public juce::ApplicationProperties,
bool isSystrayEnabled() const;
void setSystrayEnabled (bool);

/** True if the main window should start hidden in the system tray.
Only meaningful when the system tray is enabled and available. */
bool isStartHiddenEnabled() const;
void setStartHiddenEnabled (bool);

double getMidiOutLatency() const;
void setMidiOutLatency (double latencyMs);

Expand Down
8 changes: 1 addition & 7 deletions src/devicemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@

#include <element/devices.hpp>
#include "engine/jack.hpp"
#include "win32.hpp"

#if JUCE_WINDOWS
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <dbt.h>
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/pluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
#include <errno.h>
extern char* program_invocation_name;

#include "win32.hpp"

#if JUCE_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <process.h>
#include <windows.h>
#else
#include <signal.h>
#include <unistd.h>
Expand Down
12 changes: 5 additions & 7 deletions src/services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <element/engine.hpp>
#include <element/ui.hpp>
#include <element/ui/mainwindow.hpp>

#include "engine/graphmanager.hpp"
#include "presetmanager.hpp"
Expand Down Expand Up @@ -182,14 +183,11 @@ void Services::run()
{
gui->stabilizeContent();
const Node graph (session->getCurrentGraph());
auto* const props = context().settings().getUserSettings();
auto* const window = gui->getMainWindow();

if (graph.isValid())
{
// don't show plugin windows on load if the UI was hidden
if (props->getBoolValue ("mainWindowVisible", true))
gui->showPluginWindowsFor (graph);
}
// don't show plugin windows on load if the UI is hidden
if (graph.isValid() && window != nullptr && window->isOnDesktop())
gui->showPluginWindowsFor (graph);
}
}

Expand Down
44 changes: 40 additions & 4 deletions src/services/guiservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,40 @@
#include "ui/systemtray.hpp"
#include "ui/virtualkeyboardview.hpp"
#include "ui/windowmanager.hpp"
#include "win32.hpp"

#ifndef ELEMENT_USE_SYSTEM_TRAY
#define ELEMENT_USE_SYSTEM_TRAY 1
#endif

namespace element {

/** Returns true if the main window should not be shown at launch and instead
wait in the system tray. Honours the "start hidden" setting, a `--hidden`
command line flag, and on Windows the shortcut "Run: Minimized" option. */
static bool shouldStartHidden (Settings& settings)
{
if (! SystemTray::isAvailable() || ! settings.isSystrayEnabled())
return false;

if (settings.isStartHiddenEnabled())
return true;

if (JUCEApplicationBase::getCommandLineParameterArray().contains ("--hidden"))
return true;

#if JUCE_WINDOWS
STARTUPINFOW info = {};
info.cb = sizeof (info);
GetStartupInfoW (&info);
if ((info.dwFlags & STARTF_USESHOWWINDOW) != 0
&& (info.wShowWindow == SW_SHOWMINIMIZED || info.wShowWindow == SW_SHOWMINNOACTIVE || info.wShowWindow == SW_MINIMIZE))
return true;
#endif

return false;
}

//=============================================================================
class DefaultContentFactory : public ContentFactory
{
Expand Down Expand Up @@ -343,7 +370,6 @@ void GuiService::saveProperties (PropertiesFile* props)
{
props->setValue ("mainWindowState", mainWindow->getWindowStateAsString());
props->setValue ("mainWindowFullScreen", mainWindow->isFullScreen());
props->setValue ("mainWindowVisible", mainWindow->isOnDesktop() && mainWindow->isVisible());
}

if (_content)
Expand Down Expand Up @@ -673,17 +699,24 @@ void GuiService::run()

mainWindow->setContentNonOwned (content(), true);
mainWindow->centreWithSize (_content->getWidth(), _content->getHeight());
mainWindow->restoreWindowStateFromString (pf->getValue ("mainWindowState"));
mainWindow->addKeyListener (keys.get());
mainWindow->addKeyListener (commands().getKeyMappings());
_content->restoreState (pf);

if (pf->getBoolValue ("mainWindowVisible", true))
const auto windowState = pf->getValue ("mainWindowState");
if (! shouldStartHidden (settings))
{
// Create the native peer before restoring bounds so the window frame is
// known and the title bar is kept clear of docked taskbars.
mainWindow->addToDesktop();
mainWindow->restoreWindowStateFromString (windowState);
mainWindow->setVisible (true);
if (pf->getBoolValue ("mainWindowFullScreen", false))
mainWindow->setFullScreen (true);
mainWindow->addToDesktop();
}
else
{
mainWindow->restoreWindowStateFromString (windowState);
}

sibling<SessionService>()->resetChanges();
Expand Down Expand Up @@ -996,6 +1029,9 @@ bool GuiService::perform (const InvocationInfo& info)
else
{
window->addToDesktop();
// Re-run the constrainer now the native frame is known so
// the title bar isn't left under a docked taskbar.
window->setBoundsConstrained (window->getBounds());
window->toFront (true);
if (session)
showPluginWindowsFor (session->getActiveGraph(), true, false);
Expand Down
Loading
Loading