From 0529d21ffd1f6dd66b1ad8ae9ee49fe0cb526673 Mon Sep 17 00:00:00 2001 From: QC Date: Sun, 26 Jan 2014 15:39:50 +0100 Subject: [PATCH] Add support for selecting marks --- config/config.c | 3 +++ doc/simpleswitcher.1 | 17 +++++++++++++++- include/simpleswitcher.h | 9 +++++++++ source/simpleswitcher.c | 43 ++++++++++++++++++++++++++++++++-------- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/config/config.c b/config/config.c index bafad3e8..4003c611 100644 --- a/config/config.c +++ b/config/config.c @@ -48,6 +48,9 @@ Settings config = { .window_key = "F12", .run_key = "mod1+F2", .ssh_key = "mod1+F3", +#ifdef I3 + .mark_key = "mod1+F5", +#endif .location = CENTER, .wmode = VERTICAL, .inner_margin = 5 diff --git a/doc/simpleswitcher.1 b/doc/simpleswitcher.1 index c538bab0..60addb7a 100644 --- a/doc/simpleswitcher.1 +++ b/doc/simpleswitcher.1 @@ -21,9 +21,12 @@ simpleswitcher \- a simple EWMH window switcher .IR combo ] .RB [ \-dkey .IR comdo ] +.RB [ \-mkey +.IR comdo ] .RB [ \-now ] .RB [ \-rnow ] .RB [ \-snow ] +.RB [ \-mnow ] .RB [ \-term .IR terminal ] .RB [ \-loc @@ -70,7 +73,7 @@ simpleswitcher -rkey mod1+grave (grave=backtick) .RE .TP .B -skey -Change the key combination to display the ssh dialog (default: mod1-F3). +Change the key combination to display the ssh dialog (default: Alt-F3). .P .RS simpleswitcher -skey F10 @@ -80,6 +83,14 @@ simpleswitcher -skey control+shift+s simpleswitcher -skey mod1+grave (grave=backtick) .RE .TP +.B -mkey +Change the key combination to display the mark dialog (default: Alt-F5) +(only if i3 support is enabled). +.P +.RS +simpleswitcher -mkey Alt-F2 +.RE +.TP .B -now Run simpleswitcher in all-windows mode once then exit. Does not bind any keys. .TP @@ -89,6 +100,10 @@ Run simpleswitcher in run-dialog mode once then exit. Does not bind any keys. .B -snow Run simpleswitcher in ssh mode once then exit. Does not bind any keys. .TP +.B -mnow +Run simpleswitcher in mark mode once then exit. Does not bind any keys (only if i3 support is +enabled). +.TP .B -bg Set the background text color (X11 named color or hex #rrggbb) for the menu (default: #222222). .P diff --git a/include/simpleswitcher.h b/include/simpleswitcher.h index a04dac7b..102cfdd4 100644 --- a/include/simpleswitcher.h +++ b/include/simpleswitcher.h @@ -10,11 +10,17 @@ #define INTERSECT(x,y,w,h,x1,y1,w1,h1) (OVERLAP((x),(w),(x1),(w1)) && OVERLAP((y),(h),(y1),(h1))) extern const char *cache_dir; +#ifdef I3 +extern char *i3_socket_path; +#endif typedef enum { WINDOW_SWITCHER, RUN_DIALOG, SSH_DIALOG, +#ifdef I3 + MARK_DIALOG, +#endif NUM_DIALOGS, MODE_EXIT, NEXT_DIALOG @@ -82,6 +88,9 @@ typedef struct _Settings { WindowLocation location; WindowMode wmode; unsigned int inner_margin; +#ifdef I3 + char * mark_key; +#endif } Settings; extern Settings config; diff --git a/source/simpleswitcher.c b/source/simpleswitcher.c index fa9e20d5..9029038e 100644 --- a/source/simpleswitcher.c +++ b/source/simpleswitcher.c @@ -64,6 +64,7 @@ #include "simpleswitcher.h" #include "run-dialog.h" #include "ssh-dialog.h" +#include "mark-dialog.h" #define LINE_MARGIN 4 @@ -649,6 +650,12 @@ unsigned int rundialog_modmask; KeySym rundialog_keysym; unsigned int sshdialog_modmask; KeySym sshdialog_keysym; + +#ifdef I3 +unsigned int markdialog_modmask; +KeySym markdialog_keysym; +#endif + Window main_window = None; GC gc = NULL; @@ -1178,7 +1185,11 @@ void run_switcher( int fmode, SwitcherMode mode ) } else if ( mode == SSH_DIALOG ) { retv = ssh_switcher_dialog( &input ); } - +#ifdef I3 + else if ( mode == MARK_DIALOG ) { + retv = mark_switcher_dialog ( &input ); + } +#endif if ( retv == NEXT_DIALOG ) { mode = ( mode+1 )%NUM_DIALOGS; } else { @@ -1214,6 +1225,12 @@ void handle_keypress( XEvent *ev ) key == sshdialog_keysym ) { run_switcher( FORK , SSH_DIALOG ); } +#ifdef I3 + if ( ( markdialog_modmask == AnyModifier || ev->xkey.state & markdialog_modmask ) && + key == markdialog_keysym ) { + run_switcher( FORK , MARK_DIALOG ); + } +#endif } // convert a Mod+key arg to mod mask and keysym @@ -1389,21 +1406,31 @@ int main( int argc, char *argv[] ) run_switcher( NOFORK, RUN_DIALOG ); } else if ( find_arg( argc, argv, "-snow" ) >= 0 ) { run_switcher( NOFORK, SSH_DIALOG ); +#ifdef I3 + } else if ( find_arg( argc, argv, "-mnow" ) >= 0 ) { + run_switcher( NOFORK, MARK_DIALOG ); +#endif } else { // Daemon mode, Listen to key presses.. find_arg_str( argc, argv, "-key", &( config.window_key ) ); - find_arg_str( argc, argv, "-rkey",&( config.run_key ) ); - find_arg_str( argc, argv, "-skey",&( config.ssh_key ) ); - parse_key( config.window_key, &windows_modmask, &windows_keysym ); - parse_key( config.run_key, &rundialog_modmask, &rundialog_keysym ); - parse_key( config.ssh_key, &sshdialog_modmask, &sshdialog_keysym ); - - // bind key combos grab_key( windows_modmask, windows_keysym ); + + find_arg_str( argc, argv, "-rkey",&( config.run_key ) ); + parse_key( config.run_key, &rundialog_modmask, &rundialog_keysym ); grab_key( rundialog_modmask, rundialog_keysym ); + + find_arg_str( argc, argv, "-skey",&( config.ssh_key ) ); + parse_key( config.ssh_key, &sshdialog_modmask, &sshdialog_keysym ); grab_key( sshdialog_modmask, sshdialog_keysym ); + // bind key combos +#ifdef I3 + find_arg_str( argc, argv, "-mkey",&( config.mark_key ) ); + parse_key( config.mark_key, &markdialog_modmask, &markdialog_keysym ); + grab_key( markdialog_modmask, markdialog_keysym ); +#endif + XEvent ev;