Skip to content

Commit

Permalink
Add logging for Z-order/focus issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaelers committed Sep 17, 2024
1 parent 726eb6e commit 206370a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
17 changes: 16 additions & 1 deletion ui/app/platforms/windows/WindowsHarpoonLocker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "input-monitor/Harpoon.hh"

#include "debug.hh"

bool
WindowsHarpoonLocker::can_lock()
{
Expand All @@ -41,28 +43,41 @@ WindowsHarpoonLocker::block_input(bool block)
Harpoon::unblock_input();
}

UINT uPreviousState;
UINT uPreviousState = 0;
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, block, &uPreviousState, 0);
}

void
WindowsHarpoonLocker::prepare_lock()
{
TRACE_ENTRY();
active_window = GetForegroundWindow();

std::string text;
text.resize(GetWindowTextLengthA(active_window));
GetWindowTextA(active_window, text.data(), text.size() + 1);
TRACE_MSG("Save active window: {}", text);
}

void
WindowsHarpoonLocker::lock()
{
TRACE_ENTRY();
block_input(TRUE);
}

void
WindowsHarpoonLocker::unlock()
{
TRACE_ENTRY();
block_input(FALSE);
if (active_window != nullptr)
{
std::string text;
text.resize(GetWindowTextLengthA(active_window));
GetWindowTextA(active_window, text.data(), text.size() + 1);
TRACE_MSG("Restore active window: {}", text);

SetForegroundWindow(active_window);
active_window = nullptr;
}
Expand Down
13 changes: 11 additions & 2 deletions ui/app/toolkits/gtkmm/BreakWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ BreakWindow::BreakWindow(std::shared_ptr<IApplicationContext> app,

if (fullscreen_grab)
{
TRACE_MSG("Fullscreen grab");
set_app_paintable(true);
signal_draw().connect(sigc::mem_fun(*this, &BreakWindow::on_draw), false);
signal_screen_changed().connect(sigc::mem_fun(*this, &BreakWindow::on_screen_changed), false);
Expand Down Expand Up @@ -146,9 +147,16 @@ BreakWindow::BreakWindow(std::shared_ptr<IApplicationContext> app,

#if defined(PLATFORM_OS_WINDOWS)
if (WindowsForceFocus::GetForceFocusValue())
initial_ignore_activity = true;
{
TRACE_MSG("Force focus enabled");
initial_ignore_activity = true;
}

app->get_configurator()->get_value_with_default("advanced/force_focus_on_break_start", force_focus_on_break_start, true);
if (force_focus_on_break_start)
{
TRACE_MSG("Force focus on break start enabled");
}
#endif

auto core = app->get_core();
Expand Down Expand Up @@ -725,6 +733,7 @@ BreakWindow::start()
HWND hwnd = (HWND)GDK_WINDOW_HWND(gtk_widget_get_window(Gtk::Widget::gobj()));
if (force_focus_on_break_start && this->head.is_primary())
{
TRACE_MSG("Forcing window focus");
WindowsForceFocus::ForceWindowFocus(hwnd);
}
// TODO: next two lines taken from original grab() function, which is called after start(). Still needed?
Expand Down Expand Up @@ -902,7 +911,7 @@ BreakWindow::refresh_break_window()
if (WindowsForceFocus::GetForceFocusValue() && (head.is_primary()))
{
WindowsForceFocus::ForceWindowFocus(hwnd, 0); // try without blocking
}
}
}
}
#endif
2 changes: 2 additions & 0 deletions ui/app/toolkits/gtkmm/ToolkitWindows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ ToolkitWindows::ToolkitWindows(int argc, char **argv)
{
gdk_init(nullptr, nullptr);
#if defined(HAVE_HARPOON)
spdlog::info("Using Harpoon locker");
locker = std::make_shared<WindowsHarpoonLocker>();
#else
spdlog::info("Using standard locker");
locker = std::make_shared<WindowsLocker>();
#endif
}
Expand Down

0 comments on commit 206370a

Please sign in to comment.