Skip to content

Show/Hide Window Programmatically#2191

Merged
xStrom merged 19 commits intolinebender:masterfrom
newcomb-luke:hide-window
Feb 22, 2023
Merged

Show/Hide Window Programmatically#2191
xStrom merged 19 commits intolinebender:masterfrom
newcomb-luke:hide-window

Conversation

@newcomb-luke
Copy link
Contributor

This pull request closes issue #2089.
You can now hide and show a window programmatically. This is done by a new hide() method on WindowHandle, and by a new command Selector called HIDE_WINDOW. This has been implemented on the x11, GTK+, Windows, and macOS backends. Wayland does not yet seem to support hiding/showing windows through their own protocol, and window managers seem to be currently just falling back to the x11 protocol, so Wayland implementation was held off.
HIDE_WINDOW leaves the macOS only HIDE_APPLICATION Selector alone in that HIDE_WINDOW does what it says, and only hides a specific window.
The Window can be shown again by the command SHOW_WINDOW which calls the WindowHandle's bring_to_front_and_focus method, which still works as intended when the window is already shown, but when it is hidden, it shows the window again, and brings it to the front and focuses it.

@newcomb-luke newcomb-luke changed the title Hide window Show/Hide Window Programmatically May 21, 2022
@newcomb-luke
Copy link
Contributor Author

Seems to still work well with all of the new code changes that have been going on.

@yim7
Copy link

yim7 commented Sep 18, 2022

Thanks, I used your code.

hide feature works perfectly, but i can't show window after hiding it.
The deferred_queue cannot be processed because the window does not receive events after hiding. We should call the window display function directly.
And ShowWindow don't bring the window into foreground. We can use SetForegroundWindow to implement bring_to_front_and_focus

@newcomb-luke
Copy link
Contributor Author

Thanks, I used your code.

hide feature works perfectly, but i can't show window after hiding it. The deferred_queue cannot be processed because the window does not receive events after hiding. We should call the window display function directly. And ShowWindow don't bring the window into foreground. We can use SetForegroundWindow to implement bring_to_front_and_focus

What version of Windows are you trying to run it on? Maybe it is being treated differently. I've tested it on Windows 10.

How did you try to show the window? When I spawn a thread and run handle.submit_command(druid::commands::SHOW_WINDOW, (), Target::Window(window_id)), it works perfectly, and shows the window again. The program would crash when I tried to ShowWindow in a non-deferred way.

I will implement SetForegroundWindow however, to make it bring the window to the front.

@newcomb-luke
Copy link
Contributor Author

"An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user. " here

@newcomb-luke
Copy link
Contributor Author

I've added SetForegroundWindow, and everything should be up to date with master.

@xStrom
Copy link
Member

xStrom commented Jan 12, 2023

Really sorry this has been sitting for so long. Please merge master once again so we can pass CI. I will then review.

@xStrom xStrom added shell concerns the shell abstraction S-waiting-on-author waits for changes from the submitter labels Jan 12, 2023
@newcomb-luke
Copy link
Contributor Author

Synced with master.

@xStrom xStrom added S-needs-review waits for review and removed S-waiting-on-author waits for changes from the submitter labels Jan 22, 2023
@xStrom xStrom removed the S-needs-review waits for review label Feb 22, 2023
Copy link
Member

@xStrom xStrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable, thanks for your effort!

@xStrom xStrom merged commit bae9c18 into linebender:master Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

port-to-glazier shell concerns the shell abstraction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants