Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -transient-window mode #1988

Merged
merged 3 commits into from
Jun 9, 2024
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
6 changes: 6 additions & 0 deletions doc/rofi.1.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ Use Pango markup to format output wherever possible.
Make **rofi** react like a normal application window. Useful for scripts like
Clerk that are basically an application.

`-transient-window`

Make **rofi** react like a modal dialog that is transient to the currently
focused window. Useful when you use a keyboard shortcut to run and show
on the window you are working with.

`-[no-]steal-focus`

Make rofi steal focus on launch and restore close to window that held it when
Expand Down
2 changes: 2 additions & 0 deletions include/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ typedef enum {
MENU_NORMAL_WINDOW = 2,
/** ERROR dialog */
MENU_ERROR_DIALOG = 4,
/** Create transient window. */
MENU_TRANSIENT_WINDOW = 8,
} MenuFlags;

/**
Expand Down
6 changes: 6 additions & 0 deletions source/rofi.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ static void print_main_application_options(int is_term) {
is_term);
print_help_msg("-normal-window", "",
"Behave as a normal window. (experimental)", NULL, is_term);
print_help_msg("-transient-window", "",
"Behave as a modal dialog that is transient to the currently "
"focused window. (experimental)", NULL, is_term);
print_help_msg("-show", "[mode]",
"Show the mode 'mode' and exit. The mode has to be enabled.",
NULL, is_term);
Expand Down Expand Up @@ -768,6 +771,9 @@ static gboolean startup(G_GNUC_UNUSED gpointer data) {
if (find_arg("-normal-window") >= 0) {
window_flags |= MENU_NORMAL_WINDOW;
}
if (find_arg("-transient-window") >= 0) {
window_flags |= MENU_TRANSIENT_WINDOW;
}
TICK_N("Grab keyboard");
__create_window(window_flags);
TICK_N("Create Window");
Expand Down
20 changes: 19 additions & 1 deletion source/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,25 @@ void __create_window(MenuFlags menu_flags) {

TICK_N("textbox setup");
// // make it an unmanaged window
if (((menu_flags & MENU_NORMAL_WINDOW) == 0)) {
if (((menu_flags & MENU_TRANSIENT_WINDOW) != 0)) {
xcb_atom_t atoms[] = {xcb->ewmh._NET_WM_STATE_MODAL};

window_set_atom_prop(box_window, xcb->ewmh._NET_WM_STATE, atoms,
sizeof(atoms) / sizeof(xcb_atom_t));
window_set_atom_prop (box_window, xcb->ewmh._NET_WM_WINDOW_TYPE,
&(xcb->ewmh._NET_WM_WINDOW_TYPE_UTILITY), 1);
x11_disable_decoration(box_window);

xcb_window_t active_window;
xcb_get_property_cookie_t awc;
awc = xcb_ewmh_get_active_window (&xcb->ewmh, xcb->screen_nbr);

if (xcb_ewmh_get_active_window_reply(&xcb->ewmh, awc, &active_window, NULL)) {
xcb_change_property(xcb->connection, XCB_PROP_MODE_REPLACE, box_window,
XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 32,
1, &active_window);
}
} else if (((menu_flags & MENU_NORMAL_WINDOW) == 0)) {
window_set_atom_prop(box_window, xcb->ewmh._NET_WM_STATE,
&(xcb->ewmh._NET_WM_STATE_ABOVE), 1);
uint32_t values[] = {1};
Expand Down
2 changes: 1 addition & 1 deletion source/xcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@ gboolean display_late_setup(void) {
// Try to grab the keyboard as early as possible.
// We grab this using the rootwindow (as dmenu does it).
// this seems to result in the smallest delay for most people.
if (find_arg("-normal-window") >= 0) {
if (find_arg("-normal-window") >= 0 || find_arg("-transient-window") >= 0) {
return TRUE;
}
if (find_arg("-no-lazy-grab") >= 0) {
Expand Down
Loading