Added click-to-exit option. (#460)

Exit if a mouse button is pressed and released outside of the rofi
window.
This commit is contained in:
Ian Remmler 2016-09-08 15:42:41 -05:00 committed by Dave Davenport
parent e3fb17a843
commit 91e2ecf212
7 changed files with 44 additions and 5 deletions

View file

@ -130,4 +130,5 @@ Settings config = {
.scroll_method = 0,
.fake_background = "screenshot",
.window_format = "{w} {c} {t}",
.click_to_exit = TRUE,
};

View file

@ -47,6 +47,7 @@
[ -fake-transparency ]
[ -matching *method* ]
[ -tokenize ]
[ -no-click-to-exit ]
[ -threads *num* ]
[ -config *filename* ]
@ -174,9 +175,9 @@ Custom modes can be added using the internal 'script' mode. Each mode has two pa
<name>:<script>
Example: Have a mode 'Workspaces' using the `i3_switch_workspace.sh` script:
Example: Have a mode 'Workspaces' using the `i3_switch_workspaces.sh` script:
rofi -modi "window,run,ssh,Workspaces:i3_switch_workspace.sh" -show Workspaces
rofi -modi "window,run,ssh,Workspaces:i3_switch_workspaces.sh" -show Workspaces
`-case-sensitive`
@ -646,6 +647,13 @@ file (currently only supports png).
Set the name to use for mode. This is used as prompt and in combi-browser.
`-click-to-exit`
`-no-click-to-exit`
Click the mouse outside of the **rofi** window to exit.
Default: *enabled*
### Debug

View file

@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "ROFI\-MANPAGE" "" "2016-08-25" "" ""
.TH "ROFI\-MANPAGE" "" "2016-09-08" "" ""
.
.SH "NAME"
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
.
.SH "SYNOPSIS"
\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-window\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-cycle ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-matching \fImethod\fR ] [ \-tokenize ] [ \-threads \fInum\fR ] [ \-config \fIfilename\fR ]
\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-window\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-cycle ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-matching \fImethod\fR ] [ \-tokenize ] [ \-no\-click\-to\-exit ] [ \-threads \fInum\fR ] [ \-config \fIfilename\fR ]
.
.SH "DESCRIPTION"
\fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\.
@ -249,7 +249,7 @@ Custom modes can be added using the internal \'script\' mode\. Each mode has two
.IP "" 0
.
.P
Example: Have a mode \'Workspaces\' using the \fBi3_switch_workspace\.sh\fR script:
Example: Have a mode \'Workspaces\' using the \fBi3_switch_workspaces\.sh\fR script:
.
.IP "" 4
.
@ -1026,6 +1026,15 @@ Select what to use as background for fake transparency\. This can be \'backgroun
.P
Set the name to use for mode\. This is used as prompt and in combi\-browser\.
.
.P
\fB\-click\-to\-exit\fR \fB\-no\-click\-to\-exit\fR
.
.P
Click the mouse outside of the \fBrofi\fR window to exit\.
.
.P
Default: \fIenabled\fR
.
.SS "Debug"
\fB\-no\-config\fR
.

View file

@ -146,6 +146,8 @@ typedef struct
char *fake_background;
char *window_format;
/** Click outside the window to exit */
int click_to_exit;
} Settings;
/** Global Settings structure. */
extern Settings config;

View file

@ -67,6 +67,8 @@ struct RofiViewState
textbox **modi;
MenuFlags menu_flags;
int mouse_seen;
// Handlers.
void ( *x11_event_loop )( struct RofiViewState *state, xcb_generic_event_t *ev, xkb_stuff *xkb );
void ( *finalize )( struct RofiViewState *state );

View file

@ -1582,6 +1582,9 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
break;
case XCB_MOTION_NOTIFY:
{
if ( config.click_to_exit == TRUE ) {
state->mouse_seen = TRUE;
}
xcb_motion_notify_event_t *xme = (xcb_motion_notify_event_t *) ev;
if ( state->scrollbar != NULL &&
xme->event_x >= state->scrollbar->widget.x && xme->event_x < ( state->scrollbar->widget.x + state->scrollbar->widget.w ) ) {
@ -1593,6 +1596,18 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
case XCB_BUTTON_PRESS:
rofi_view_mouse_navigation ( state, (xcb_button_press_event_t *) ev );
break;
case XCB_BUTTON_RELEASE:
if ( config.click_to_exit == TRUE ) {
if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
xcb_button_release_event_t *bre = (xcb_button_release_event_t *) ev;
if ( ( state->mouse_seen == FALSE ) && ( bre->event != CacheState.main_window ) ) {
state->quit = TRUE;
state->retv = MENU_CANCEL;
}
}
state->mouse_seen = FALSE;
}
break;
// Paste event.
case XCB_SELECTION_NOTIFY:
rofi_view_paste ( state, (xcb_selection_notify_event_t *) ev );

View file

@ -190,6 +190,8 @@ static XrmOption xrmOptions[] = {
"Background to use for fake transparency. (background or screenshot)", CONFIG_DEFAULT },
{ xrm_String, "window-format", { .str = &config.window_format }, NULL,
"Window Format. w (desktop name), t (title), n (name), r (role), c (class)", CONFIG_DEFAULT },
{ xrm_Boolean, "click-to-exit", { .num = &config.click_to_exit }, NULL,
"Click outside the window to exit", CONFIG_DEFAULT },
};
// Dynamic options.