Skip to content

Commit

Permalink
Add -transient-window mode
Browse files Browse the repository at this point in the history
This will add a new mode for the rofi window so when you run it with
-transient-window

instead of
-normal-window

it will get the currently focused window and then use that as the parent window and set itself as transient of that window.  It is useful so that when you  use a keyboard shortcut to start rofi it will always popup on the window you are working on and so it doesn't make you refocus/move your head on large monitors :)
  • Loading branch information
pijulius committed Jun 9, 2024
1 parent bd0ba45 commit a9bf0e6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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
3 changes: 3 additions & 0 deletions source/rofi.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,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

0 comments on commit a9bf0e6

Please sign in to comment.