diff --git a/config/config.def.c b/config/config.def.c index 47e63a3c..59944c97 100644 --- a/config/config.def.c +++ b/config/config.def.c @@ -130,5 +130,7 @@ Settings config = { .combi_modi = "window,run", /** Fuzzy matching. */ .fuzzy = FALSE, + /** Monitor */ + .monitor = -1, }; diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index eba9bdff..76447a94 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -395,6 +395,11 @@ The following options are further explained in the theming section: When one entry is left, automatically select this. +`-m` *num* +`-monitor` *num* + + Select (Xinerama) monitor to display **rofi** on. + ### PATTERN setting `-terminal` diff --git a/doc/rofi.1 b/doc/rofi.1 index 658aaa2c..7215f477 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ROFI\-MANPAGE" "" "July 2015" "" "" +.TH "ROFI\-MANPAGE" "" "August 2015" "" "" . .SH "NAME" \fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement @@ -719,6 +719,19 @@ When one entry is left, automatically select this\. . .IP "" 0 . +.P +\fB\-m\fR \fInum\fR \fB\-monitor\fR \fInum\fR +. +.IP "" 4 +. +.nf + +Select (Xinerama) monitor to display **rofi** on\. +. +.fi +. +.IP "" 0 +. .SS "PATTERN setting" \fB\-terminal\fR . diff --git a/include/rofi.h b/include/rofi.h index 955ffd9d..b626785f 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -228,6 +228,8 @@ typedef struct _Settings char *combi_modi; /** Fuzzy match */ unsigned int fuzzy; + /** Monitors */ + int monitor; } Settings; /** Global Settings structure. */ diff --git a/include/x11-helper.h b/include/x11-helper.h index 56ebc8b1..d0597d15 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -65,6 +65,8 @@ int window_send_message ( Display *display, Window target, Window subject, // find the dimensions of the monitor displaying point x,y void monitor_dimensions ( Display *display, Screen *screen, int x, int y, workarea *mon ); +// Find the dimensions of the monitor specified by user. +int monitor_get_dimension ( Display *display, Screen *screen, int monitor, workarea *mon ); /** * @param display The display. diff --git a/source/rofi.c b/source/rofi.c index 1815354d..e2aa0777 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1870,7 +1870,7 @@ static void main_loop_x11_event_handler ( void ) * * returns TRUE when mainloop should be stopped. */ -static int main_loop_signal_handler ( char command , int quiet ) +static int main_loop_signal_handler ( char command, int quiet ) { if ( command == 'c' ) { if ( !quiet ) { @@ -2105,11 +2105,11 @@ int main ( int argc, char *argv[] ) FD_SET ( x11_fd, &in_fds ); FD_SET ( pfds[0], &in_fds ); - // Wait for X Event or a message on signal pipe + // Wait for X Event or a message on signal pipe if ( select ( MAX ( x11_fd, pfds[0] ) + 1, &in_fds, 0, 0, NULL ) >= 0 ) { // X11 if ( FD_ISSET ( x11_fd, &in_fds ) ) { - main_loop_x11_event_handler(); + main_loop_x11_event_handler (); } // Signal Pipe if ( FD_ISSET ( pfds[0], &in_fds ) ) { @@ -2117,7 +2117,7 @@ int main ( int argc, char *argv[] ) char c; read ( pfds[0], &c, 1 ); // Process the signal in the main_loop. - if(main_loop_signal_handler(c, quiet)) { + if ( main_loop_signal_handler ( c, quiet ) ) { break; } } diff --git a/source/x11-helper.c b/source/x11-helper.c index 395b176a..907e0af4 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -139,6 +139,29 @@ int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned l } +int monitor_get_dimension ( Display *display, Screen *screen, int monitor, workarea *mon ) +{ + memset ( mon, 0, sizeof ( workarea ) ); + mon->w = WidthOfScreen ( screen ); + mon->h = HeightOfScreen ( screen ); + // locate the current monitor + if ( XineramaIsActive ( display ) ) { + int monitors; + XineramaScreenInfo *info = XineramaQueryScreens ( display, &monitors ); + + if ( info ) { + if ( monitor >= 0 && monitor < monitors ) { + mon->x = info[monitor].x_org; + mon->y = info[monitor].y_org; + mon->w = info[monitor].width; + mon->h = info[monitor].height; + return TRUE; + } + XFree ( info ); + } + } + return FALSE; +} // find the dimensions of the monitor displaying point x,y void monitor_dimensions ( Display *display, Screen *screen, int x, int y, workarea *mon ) { @@ -203,6 +226,12 @@ void monitor_active ( Display *display, workarea *mon ) Window id; Atom type; int count; + if ( config.monitor >= 0 ) { + if ( monitor_get_dimension ( display, screen, config.monitor, mon ) ) { + return; + } + fprintf ( stderr, "Failed to find selected monitor.\n" ); + } if ( window_get_prop ( display, root, netatoms[_NET_ACTIVE_WINDOW], &type, &count, &id, sizeof ( Window ) ) && type == XA_WINDOW && count > 0 ) { XWindowAttributes attr; diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 2cbb3573..67b3b43f 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -123,7 +123,10 @@ static XrmOption xrmOptions[] = { { xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL }, { xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL }, { xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL }, - { xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL } + { xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL }, + { xrm_Number, "monitor", { .snum = &config.monitor }, NULL }, + /* Alias for dmenu compatibility. */ + { xrm_Number, "m", { .snum = &config.monitor }, NULL } }; // Dynamic options.