1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-01-27 15:25:24 -05:00

fast toggling between window list modes

This commit is contained in:
seanpringle 2012-11-18 17:43:06 +10:00
parent 39803742c0
commit cba553e2e2

View file

@ -539,6 +539,9 @@ client* window_client(Window win)
unsigned int all_windows_modmask; KeySym all_windows_keysym; unsigned int all_windows_modmask; KeySym all_windows_keysym;
unsigned int desktop_windows_modmask; KeySym desktop_windows_keysym; unsigned int desktop_windows_modmask; KeySym desktop_windows_keysym;
// flags to set if we switch modes on the fly
int run_all_windows = 0, run_desktop_windows = 0, current_mode = 0;
Window main_window = None;
#include "textbox.c" #include "textbox.c"
@ -568,8 +571,19 @@ int menu(char **lines, char **input, char *prompt, int selected, Time *time)
int w = config_menu_width < 101 ? (mon.w/100)*config_menu_width: config_menu_width; int w = config_menu_width < 101 ? (mon.w/100)*config_menu_width: config_menu_width;
int x = mon.x + (mon.w - w)/2; int x = mon.x + (mon.w - w)/2;
Window box = XCreateSimpleWindow(display, root, x, 0, w, 300, 1, color_get(config_menu_bc), color_get(config_menu_bg)); Window box;
// main window isn't explictly destroyed in case we switch modes. reusing it prevents flicker
if (main_window != None)
{
box = main_window;
XMoveResizeWindow(display, box, x, 0, w, 300);
}
else
{
box = XCreateSimpleWindow(display, root, x, 0, w, 300, 1, color_get(config_menu_bc), color_get(config_menu_bg));
XSelectInput(display, box, ExposureMask); XSelectInput(display, box, ExposureMask);
}
// make it an unmanaged window // make it an unmanaged window
window_set_atom_prop(box, netatoms[_NET_WM_STATE], &netatoms[_NET_WM_STATE_ABOVE], 1); window_set_atom_prop(box, netatoms[_NET_WM_STATE], &netatoms[_NET_WM_STATE_ABOVE], 1);
@ -660,10 +674,18 @@ int menu(char **lines, char **input, char *prompt, int selected, Time *time)
KeySym key = XkbKeycodeToKeysym(display, ev.xkey.keycode, 0, 0); KeySym key = XkbKeycodeToKeysym(display, ev.xkey.keycode, 0, 0);
if (key == XK_Escape if (key == XK_Escape
// pressing one of the global key bindings closes the switcher. this allows fast closing of the menu if an item is not selected
|| ((all_windows_modmask == AnyModifier || ev.xkey.state & all_windows_modmask) && key == all_windows_keysym) || ((all_windows_modmask == AnyModifier || ev.xkey.state & all_windows_modmask) && key == all_windows_keysym)
|| ((desktop_windows_modmask == AnyModifier || ev.xkey.state & desktop_windows_modmask) && key == desktop_windows_keysym)) || ((desktop_windows_modmask == AnyModifier || ev.xkey.state & desktop_windows_modmask) && key == desktop_windows_keysym))
{ {
aborted = 1; aborted = 1;
// pressing a global key binding that does not match the current mode switches modes on the fly. this allow fast flipping back and forth
if (current_mode == DESKTOPWINDOWS && (all_windows_modmask == AnyModifier || ev.xkey.state & all_windows_modmask) && key == all_windows_keysym)
run_all_windows = 1;
if (current_mode == ALLWINDOWS && (desktop_windows_modmask == AnyModifier || ev.xkey.state & desktop_windows_modmask) && key == desktop_windows_keysym)
run_desktop_windows = 1;
break; break;
} }
@ -691,7 +713,7 @@ int menu(char **lines, char **input, char *prompt, int selected, Time *time)
textbox_free(text); textbox_free(text);
for (i = 0; i < max_lines; i++) for (i = 0; i < max_lines; i++)
textbox_free(boxes[i]); textbox_free(boxes[i]);
XDestroyWindow(display, box);
free(filtered); free(filtered);
free(line_map); free(line_map);
@ -704,6 +726,26 @@ int menu(char **lines, char **input, char *prompt, int selected, Time *time)
void run_switcher(int mode, int fmode) void run_switcher(int mode, int fmode)
{ {
// TODO: this whole function is messy. build a nicer solution // TODO: this whole function is messy. build a nicer solution
// we fork because it's technically possible to have multiple window
// lists up at once on a zaphod multihead X setup.
// this also happens to isolate the Xft font stuff in a child process
// that gets cleaned up every time. that library shows some valgrind
// strangeness...
if (fmode == FORK)
{
if (fork()) return;
display = XOpenDisplay(0);
XSync(display, True);
}
do {
if (run_all_windows) mode = ALLWINDOWS;
if (run_desktop_windows) mode = DESKTOPWINDOWS;
run_all_windows = run_desktop_windows = 0;
current_mode = mode;
char pattern[50], **list = NULL; char pattern[50], **list = NULL;
int i, classfield = 0, plen = 0, lines = 0; int i, classfield = 0, plen = 0, lines = 0;
unsigned long desktops = 0, current_desktop = 0; unsigned long desktops = 0, current_desktop = 0;
@ -775,15 +817,6 @@ void run_switcher(int mode, int fmode)
list[lines++] = line; list[lines++] = line;
} }
} }
if (fmode == NOFORK || !fork())
{
// we fork because it's technically possible to have multiple window
// lists up at once on a zaphod multihead X setup.
// this also happens to isolate the Xft font stuff in a child process
// that gets cleaned up every time. that library shows some valgrind
// strangeness...
display = XOpenDisplay(0);
XSync(display, True);
char *input = NULL; char *input = NULL;
Time time; Time time;
int n = menu(list, &input, "> ", 1, &time); int n = menu(list, &input, "> ", 1, &time);
@ -805,13 +838,17 @@ void run_switcher(int mode, int fmode)
{ {
exec_cmd(input); exec_cmd(input);
} }
exit(EXIT_SUCCESS); for (i = 0; i < lines; i++)
} free(list[i]);
for (i = 0; i < lines; i++) free(list[i]);
free(list); free(list);
} }
free(wins); free(wins);
winlist_free(ids); winlist_free(ids);
}
while (run_all_windows || run_desktop_windows);
if (fmode == FORK)
exit(EXIT_SUCCESS);
} }
// KeyPress event // KeyPress event