mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Use XRandr to get monitor layout instead of xinerama.
* You can now specify monitor by name, or primary status.
This commit is contained in:
parent
26d1e64b22
commit
df7468b491
12 changed files with 345 additions and 236 deletions
|
@ -112,7 +112,7 @@ Settings config = {
|
|||
.tokenize = TRUE,
|
||||
.regex = FALSE,
|
||||
/** Monitor */
|
||||
.monitor = -1,
|
||||
.monitor = "-1",
|
||||
/** set line margin */
|
||||
.line_margin = 2,
|
||||
/** Set filter */
|
||||
|
|
|
@ -86,7 +86,7 @@ dnl ---------------------------------------------------------------------
|
|||
dnl PKG_CONFIG based dependencies
|
||||
dnl ---------------------------------------------------------------------
|
||||
PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.40])
|
||||
GW_CHECK_XCB([xcb-aux xcb-xkb xkbcommon >= 0.5.0 xkbcommon-x11 xcb-ewmh xcb-xinerama xcb-icccm xcb-xrm])
|
||||
GW_CHECK_XCB([xcb-aux xcb-xkb xkbcommon >= 0.5.0 xkbcommon-x11 xcb-ewmh xcb-icccm xcb-xrm xcb-randr])
|
||||
PKG_CHECK_MODULES([pango], [pango pangocairo])
|
||||
PKG_CHECK_MODULES([cairo], [cairo cairo-xcb])
|
||||
PKG_CHECK_MODULES([libsn], [libstartup-notification-1.0])
|
||||
|
|
|
@ -370,10 +370,16 @@ Default: *5000*
|
|||
When one entry is left, automatically select it.
|
||||
|
||||
`-m` *num*
|
||||
|
||||
`-m` *name*
|
||||
|
||||
`-monitor` *num*
|
||||
|
||||
`-monitor` *name*
|
||||
|
||||
Select (Xinerama) monitor to display **rofi** on.
|
||||
Negative numbers are handled differently:
|
||||
As input it accepts: *primary* (if primary output is set), the *xrandr* output name or integer number (in order of
|
||||
detection). Negative numbers are handled differently:
|
||||
|
||||
* **-1**: the currently focused monitor.
|
||||
* **-2**: the currently focused window (i.e. rofi will be displayed on top of the focused window).
|
||||
|
@ -384,6 +390,8 @@ Negative numbers are handled differently:
|
|||
|
||||
Default: *-1*
|
||||
|
||||
See `rofi -h` output for the detected monitors, their position and size.
|
||||
|
||||
### PATTERN setting
|
||||
|
||||
`-terminal`
|
||||
|
|
18
doc/rofi.1
18
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 2016" "" ""
|
||||
.TH "ROFI\-MANPAGE" "" "2016-08-18" "" ""
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
|
||||
|
@ -621,10 +621,19 @@ Default: \fI5000\fR
|
|||
When one entry is left, automatically select it\.
|
||||
.
|
||||
.P
|
||||
\fB\-m\fR \fInum\fR \fB\-monitor\fR \fInum\fR
|
||||
\fB\-m\fR \fInum\fR
|
||||
.
|
||||
.P
|
||||
Select (Xinerama) monitor to display \fBrofi\fR on\. Negative numbers are handled differently:
|
||||
\fB\-m\fR \fIname\fR
|
||||
.
|
||||
.P
|
||||
\fB\-monitor\fR \fInum\fR
|
||||
.
|
||||
.P
|
||||
\fB\-monitor\fR \fIname\fR
|
||||
.
|
||||
.P
|
||||
Select (Xinerama) monitor to display \fBrofi\fR on\. As input it accepts: \fIprimary\fR (if primary output is set), the \fIxrandr\fR output name or integer number (in order of detection)\. Negative numbers are handled differently:
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
\fB\-1\fR: the currently focused monitor\.
|
||||
|
@ -646,6 +655,9 @@ Default: \fI\-1\fR
|
|||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
See \fBrofi \-h\fR output for the detected monitors, their position and size\.
|
||||
.
|
||||
.SS "PATTERN setting"
|
||||
\fB\-terminal\fR
|
||||
.
|
||||
|
|
|
@ -109,7 +109,7 @@ typedef struct
|
|||
unsigned int tokenize;
|
||||
unsigned int regex;
|
||||
/** Monitors */
|
||||
int monitor;
|
||||
char *monitor;
|
||||
/** Line margin */
|
||||
unsigned int line_margin;
|
||||
/** filter */
|
||||
|
|
|
@ -45,18 +45,21 @@ enum { EWMH_ATOMS ( ATOM_ENUM ), NUM_NETATOMS };
|
|||
|
||||
extern const char *netatom_names[];
|
||||
extern xcb_atom_t netatoms[NUM_NETATOMS];
|
||||
typedef struct
|
||||
{
|
||||
int x, y, w, h;
|
||||
int l, r, t, b;
|
||||
} workarea;
|
||||
|
||||
void monitor_active ( workarea *mon );
|
||||
typedef struct _workarea
|
||||
{
|
||||
int monitor_id;
|
||||
int primary;
|
||||
int x, y, w, h;
|
||||
char *name;
|
||||
struct _workarea *next;
|
||||
} workarea;
|
||||
int monitor_active ( workarea *mon );
|
||||
|
||||
// find the dimensions of the monitor displaying point x,y
|
||||
void monitor_dimensions ( int x, int y, workarea *mon );
|
||||
// Find the dimensions of the monitor specified by user.
|
||||
int monitor_get_dimension ( int monitor, workarea *mon );
|
||||
int monitor_get_dimension ( int monitor_id, workarea *mon );
|
||||
int monitor_get_smallest_size ( void );
|
||||
|
||||
/**
|
||||
|
@ -145,5 +148,12 @@ void x11_helper_set_cairo_rgba ( cairo_t *d, Color col );
|
|||
* @returns a cairo surface with the background image of the desktop.
|
||||
*/
|
||||
cairo_surface_t * x11_helper_get_bg_surface ( void );
|
||||
|
||||
/**
|
||||
* Creates an internal represenation of the available monitors.
|
||||
* Used for positioning rofi.
|
||||
*/
|
||||
void x11_build_monitor_layout ( void );
|
||||
void x11_dump_monitor_layout ( void );
|
||||
/*@}*/
|
||||
#endif
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_ewmh.h>
|
||||
|
||||
/**
|
||||
* Structure to keep xcb stuff around.
|
||||
*/
|
||||
|
@ -18,7 +19,7 @@ struct _xcb_stuff
|
|||
int screen_nbr;
|
||||
SnDisplay *sndisplay;
|
||||
SnLauncheeContext *sncontext;
|
||||
gboolean has_xinerama;
|
||||
struct _workarea *monitors;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -477,16 +477,14 @@ int config_sanity_check ( void )
|
|||
// Check size
|
||||
{
|
||||
int ssize = monitor_get_smallest_size ( );
|
||||
if ( config.monitor >= 0 ) {
|
||||
workarea mon;
|
||||
if ( monitor_get_dimension ( config.monitor, &mon ) ) {
|
||||
if ( monitor_active ( &mon ) ) {
|
||||
ssize = MIN ( mon.w, mon.h );
|
||||
}
|
||||
else{
|
||||
g_string_append_printf ( msg, "\t<b>config.monitor</b>=%d Could not find monitor.\n", config.monitor );
|
||||
g_string_append_printf ( msg, "\t<b>config.monitor</b>=%s Could not find monitor.\n", config.monitor );
|
||||
ssize = 0;
|
||||
}
|
||||
}
|
||||
// Have todo an estimate here.
|
||||
if ( ( 2 * ( config.padding + config.menu_bw ) ) > ( 0.9 * ssize ) ) {
|
||||
g_string_append_printf ( msg, "\t<b>config.padding+config.menu_bw</b>=%d is too big for the minimum size of the monitor: %d.\n",
|
||||
|
@ -511,7 +509,7 @@ int config_sanity_check ( void )
|
|||
pango_font_description_free ( pfd );
|
||||
}
|
||||
|
||||
if ( config.monitor == -3 ) {
|
||||
if ( g_strcmp0 ( config.monitor, "-3" ) == 0 ) {
|
||||
// On -3, set to location 1.
|
||||
config.location = 1;
|
||||
config.fullscreen = 0;
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_ewmh.h>
|
||||
#include <xcb/xinerama.h>
|
||||
#include <xcb/xkb.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <xkbcommon/xkbcommon-compose.h>
|
||||
|
@ -261,6 +260,7 @@ static void help ( G_GNUC_UNUSED int argc, char **argv )
|
|||
printf ( "Global options:\n" );
|
||||
print_options ();
|
||||
printf ( "\n" );
|
||||
x11_dump_monitor_layout ();
|
||||
printf ( "For more information see: man rofi\n" );
|
||||
#ifdef GIT_VERSION
|
||||
printf ( "Version: "GIT_VERSION "\n" );
|
||||
|
@ -268,6 +268,7 @@ static void help ( G_GNUC_UNUSED int argc, char **argv )
|
|||
printf ( "Version: "VERSION "\n" );
|
||||
#endif
|
||||
printf ( "Bugreports: "PACKAGE_BUGREPORT "\n" );
|
||||
printf ( "Support: #rofi @ freenode.net\n" );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -663,6 +664,8 @@ int main ( int argc, char *argv[] )
|
|||
|
||||
xcb->screen = xcb_aux_get_screen ( xcb->connection, xcb->screen_nbr );
|
||||
|
||||
x11_build_monitor_layout ();
|
||||
|
||||
xcb_intern_atom_cookie_t *ac = xcb_ewmh_init_atoms ( xcb->connection, &xcb->ewmh );
|
||||
xcb_generic_error_t *errors = NULL;
|
||||
xcb_ewmh_init_atoms_replies ( &xcb->ewmh, ac, &errors );
|
||||
|
@ -755,16 +758,6 @@ int main ( int argc, char *argv[] )
|
|||
fprintf ( stderr, "Connection has error\n" );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
const xcb_query_extension_reply_t *er = xcb_get_extension_data ( xcb->connection, &xcb_xinerama_id );
|
||||
if ( er ) {
|
||||
if ( er->present ) {
|
||||
xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb->connection );
|
||||
xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb->connection, is_active_req, NULL );
|
||||
xcb->has_xinerama = is_active->state;
|
||||
free ( is_active );
|
||||
}
|
||||
}
|
||||
main_loop = g_main_loop_new ( NULL, FALSE );
|
||||
|
||||
TICK_N ( "Setup mainloop" );
|
||||
|
|
|
@ -1152,7 +1152,7 @@ static void rofi_view_paste ( RofiViewState *state, xcb_selection_notify_event_t
|
|||
}
|
||||
// Insert string move cursor.
|
||||
textbox_insert ( state->text, state->text->cursor, text, dl );
|
||||
textbox_cursor ( state->text, state->text->cursor + g_utf8_strlen(text, -1) );
|
||||
textbox_cursor ( state->text, state->text->cursor + g_utf8_strlen ( text, -1 ) );
|
||||
// Force a redraw and refiltering of the text.
|
||||
state->update = TRUE;
|
||||
state->refilter = TRUE;
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include <cairo-xcb.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xinerama.h>
|
||||
#include <xcb/randr.h>
|
||||
#include "xcb-internal.h"
|
||||
#include "xcb.h"
|
||||
#include "settings.h"
|
||||
|
@ -59,7 +59,7 @@ struct _xcb_stuff xcb_int = {
|
|||
.screen_nbr = -1,
|
||||
.sndisplay = NULL,
|
||||
.sncontext = NULL,
|
||||
.has_xinerama = FALSE,
|
||||
.monitors = NULL
|
||||
};
|
||||
xcb_stuff *xcb = &xcb_int;
|
||||
|
||||
|
@ -154,102 +154,160 @@ void window_set_atom_prop ( xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms,
|
|||
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, w, prop, XCB_ATOM_ATOM, 32, count, atoms );
|
||||
}
|
||||
|
||||
/****
|
||||
* Code used to get monitor layout.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Free monitor structure.
|
||||
*/
|
||||
static void x11_monitor_free ( workarea *m )
|
||||
{
|
||||
g_free ( m->name );
|
||||
g_free ( m );
|
||||
}
|
||||
|
||||
static void x11_monitors_free ( void )
|
||||
{
|
||||
while ( xcb->monitors != NULL ) {
|
||||
workarea *m = xcb->monitors;
|
||||
xcb->monitors = m->next;
|
||||
x11_monitor_free ( m );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create monitor based on output id
|
||||
*/
|
||||
static workarea * x11_get_monitor_from_output ( xcb_randr_output_t out )
|
||||
{
|
||||
xcb_randr_get_output_info_reply_t *op_reply;
|
||||
xcb_randr_get_crtc_info_reply_t *crtc_reply;
|
||||
xcb_randr_get_output_info_cookie_t it = xcb_randr_get_output_info ( xcb->connection, out, XCB_CURRENT_TIME );
|
||||
op_reply = xcb_randr_get_output_info_reply ( xcb->connection, it, NULL );
|
||||
if ( op_reply->crtc == XCB_NONE ) {
|
||||
free ( op_reply );
|
||||
return NULL;
|
||||
}
|
||||
xcb_randr_get_crtc_info_cookie_t ct = xcb_randr_get_crtc_info ( xcb->connection, op_reply->crtc, XCB_CURRENT_TIME );
|
||||
crtc_reply = xcb_randr_get_crtc_info_reply ( xcb->connection, ct, NULL );
|
||||
if ( !crtc_reply ) {
|
||||
free ( op_reply );
|
||||
return NULL;
|
||||
}
|
||||
workarea *retv = g_malloc0 ( sizeof ( workarea ) );
|
||||
retv->x = crtc_reply->x;
|
||||
retv->y = crtc_reply->y;
|
||||
retv->w = crtc_reply->width;
|
||||
retv->h = crtc_reply->height;
|
||||
|
||||
char *tname = (char *) xcb_randr_get_output_info_name ( op_reply );
|
||||
int tname_len = xcb_randr_get_output_info_name_length ( op_reply );
|
||||
|
||||
retv->name = g_malloc0 ( ( tname_len + 1 ) * sizeof ( char ) );
|
||||
memcpy ( retv->name, tname, tname_len );
|
||||
|
||||
free ( crtc_reply );
|
||||
free ( op_reply );
|
||||
return retv;
|
||||
}
|
||||
|
||||
void x11_build_monitor_layout ()
|
||||
{
|
||||
if ( xcb->monitors ) {
|
||||
return;
|
||||
}
|
||||
xcb_randr_get_screen_resources_current_reply_t *res_reply;
|
||||
xcb_randr_get_screen_resources_current_cookie_t src;
|
||||
src = xcb_randr_get_screen_resources_current ( xcb->connection, xcb->screen->root );
|
||||
res_reply = xcb_randr_get_screen_resources_current_reply ( xcb->connection, src, NULL );
|
||||
if ( !res_reply ) {
|
||||
return; //just report error
|
||||
}
|
||||
int mon_num = xcb_randr_get_screen_resources_current_outputs_length ( res_reply );
|
||||
xcb_randr_output_t *ops = xcb_randr_get_screen_resources_current_outputs ( res_reply );
|
||||
|
||||
// Get primary.
|
||||
xcb_randr_get_output_primary_cookie_t pc = xcb_randr_get_output_primary ( xcb->connection, xcb->screen->root );
|
||||
xcb_randr_get_output_primary_reply_t *pc_rep = xcb_randr_get_output_primary_reply ( xcb->connection, pc, NULL );
|
||||
|
||||
for ( int i = mon_num - 1; i >= 0; i-- ) {
|
||||
workarea *w = x11_get_monitor_from_output ( ops[i] );
|
||||
if ( w ) {
|
||||
w->next = xcb->monitors;
|
||||
xcb->monitors = w;
|
||||
if ( pc_rep && pc_rep->output == ops[i] ) {
|
||||
w->primary = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Number monitor
|
||||
int index = 0;
|
||||
for ( workarea *iter = xcb->monitors; iter; iter = iter->next ) {
|
||||
iter->monitor_id = index++;
|
||||
}
|
||||
// If exists, free primary output reply.
|
||||
if ( pc_rep ) {
|
||||
free ( pc_rep );
|
||||
}
|
||||
free ( res_reply );
|
||||
}
|
||||
|
||||
void x11_dump_monitor_layout ( void )
|
||||
{
|
||||
int is_term = isatty ( fileno ( stdout ) );
|
||||
printf ( "Monitor layout:\n" );
|
||||
for ( workarea *iter = xcb->monitors; iter; iter = iter->next ) {
|
||||
printf ( "%s ID%s: %d", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->monitor_id );
|
||||
if ( iter->primary ) {
|
||||
printf ( " (primary)" );
|
||||
}
|
||||
printf ( "\n" );
|
||||
printf ( "%s name%s: %s\n", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->name );
|
||||
printf ( "%s position%s: %d,%d\n", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->x, iter->y );
|
||||
printf ( "%s size%s: %d,%d\n", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->w, iter->h );
|
||||
printf ( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
int monitor_get_smallest_size ( void )
|
||||
{
|
||||
xcb_generic_error_t *error;
|
||||
int size = MIN ( xcb->screen->width_in_pixels, xcb->screen->height_in_pixels );
|
||||
|
||||
if ( !xcb->has_xinerama ) {
|
||||
return size;
|
||||
for ( workarea *iter = xcb->monitors; iter; iter = iter->next ) {
|
||||
size = MIN ( iter->w, size );
|
||||
size = MIN ( iter->h, size );
|
||||
}
|
||||
|
||||
xcb_xinerama_query_screens_cookie_t cookie_screen;
|
||||
|
||||
cookie_screen = xcb_xinerama_query_screens ( xcb->connection );
|
||||
xcb_xinerama_query_screens_reply_t *query_screens;
|
||||
query_screens = xcb_xinerama_query_screens_reply ( xcb->connection, cookie_screen, &error );
|
||||
if ( error ) {
|
||||
fprintf ( stderr, "Error getting screen info\n" );
|
||||
return size;
|
||||
}
|
||||
xcb_xinerama_screen_info_t *screens = xcb_xinerama_query_screens_screen_info ( query_screens );
|
||||
int len = xcb_xinerama_query_screens_screen_info_length ( query_screens );
|
||||
for ( int i = 0; i < len; i++ ) {
|
||||
xcb_xinerama_screen_info_t *info = &screens[i];
|
||||
size = MIN ( info->width, size );
|
||||
size = MIN ( info->height, size );
|
||||
}
|
||||
free ( query_screens );
|
||||
|
||||
return size;
|
||||
}
|
||||
int monitor_get_dimension ( int monitor, workarea *mon )
|
||||
int monitor_get_dimension ( int monitor_id, workarea *mon )
|
||||
{
|
||||
xcb_generic_error_t *error = NULL;
|
||||
memset ( mon, 0, sizeof ( workarea ) );
|
||||
mon->w = xcb->screen->width_in_pixels;
|
||||
mon->h = xcb->screen->height_in_pixels;
|
||||
|
||||
if ( !xcb->has_xinerama ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
xcb_xinerama_query_screens_cookie_t cookie_screen;
|
||||
cookie_screen = xcb_xinerama_query_screens ( xcb->connection );
|
||||
xcb_xinerama_query_screens_reply_t *query_screens;
|
||||
query_screens = xcb_xinerama_query_screens_reply ( xcb->connection, cookie_screen, &error );
|
||||
if ( error ) {
|
||||
fprintf ( stderr, "Error getting screen info\n" );
|
||||
return FALSE;
|
||||
}
|
||||
xcb_xinerama_screen_info_t *screens = xcb_xinerama_query_screens_screen_info ( query_screens );
|
||||
int len = xcb_xinerama_query_screens_screen_info_length ( query_screens );
|
||||
if ( monitor < len ) {
|
||||
xcb_xinerama_screen_info_t *info = &screens[monitor];
|
||||
mon->w = info->width;
|
||||
mon->h = info->height;
|
||||
mon->x = info->x_org;
|
||||
mon->y = info->y_org;
|
||||
free ( query_screens );
|
||||
workarea *iter = NULL;
|
||||
for ( iter = xcb->monitors; iter; iter = iter->next ) {
|
||||
if ( iter->monitor_id == monitor_id ) {
|
||||
*mon = *iter;
|
||||
return TRUE;
|
||||
}
|
||||
free ( query_screens );
|
||||
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
// find the dimensions of the monitor displaying point x,y
|
||||
void monitor_dimensions ( int x, int y, workarea *mon )
|
||||
{
|
||||
xcb_generic_error_t *error = NULL;
|
||||
memset ( mon, 0, sizeof ( workarea ) );
|
||||
mon->w = xcb->screen->width_in_pixels;
|
||||
mon->h = xcb->screen->height_in_pixels;
|
||||
|
||||
if ( !xcb->has_xinerama ) {
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_xinerama_query_screens_cookie_t cookie_screen;
|
||||
cookie_screen = xcb_xinerama_query_screens ( xcb->connection );
|
||||
xcb_xinerama_query_screens_reply_t *query_screens;
|
||||
query_screens = xcb_xinerama_query_screens_reply ( xcb->connection, cookie_screen, &error );
|
||||
if ( error ) {
|
||||
fprintf ( stderr, "Error getting screen info\n" );
|
||||
return;
|
||||
}
|
||||
xcb_xinerama_screen_info_t *screens = xcb_xinerama_query_screens_screen_info ( query_screens );
|
||||
int len = xcb_xinerama_query_screens_screen_info_length ( query_screens );
|
||||
for ( int i = 0; i < len; i++ ) {
|
||||
xcb_xinerama_screen_info_t *info = &screens[i];
|
||||
if ( INTERSECT ( x, y, 1, 1, info->x_org, info->y_org, info->width, info->height ) ) {
|
||||
mon->w = info->width;
|
||||
mon->h = info->height;
|
||||
mon->x = info->x_org;
|
||||
mon->y = info->y_org;
|
||||
for ( workarea *iter = xcb->monitors; iter; iter = iter->next ) {
|
||||
if ( INTERSECT ( x, y, 1, 1, iter->x, iter->y, iter->w, iter->h ) ) {
|
||||
*mon = *iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free ( query_screens );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -278,30 +336,54 @@ static int pointer_get ( xcb_window_t root, int *x, int *y )
|
|||
}
|
||||
|
||||
// determine which monitor holds the active window, or failing that the mouse pointer
|
||||
void monitor_active ( workarea *mon )
|
||||
int monitor_active ( workarea *mon )
|
||||
{
|
||||
xcb_window_t root = xcb->screen->root;
|
||||
int x, y;
|
||||
|
||||
if ( config.monitor >= 0 ) {
|
||||
if ( monitor_get_dimension ( config.monitor, mon ) ) {
|
||||
return;
|
||||
if ( config.monitor != NULL ) {
|
||||
for ( workarea *iter = xcb->monitors; iter; iter = iter->next ) {
|
||||
if ( g_strcmp0 ( config.monitor, iter->name ) == 0 ) {
|
||||
*mon = *iter;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Grab primary.
|
||||
if ( g_strcmp0 ( config.monitor, "primary" ) == 0 ) {
|
||||
for ( workarea *iter = xcb->monitors; iter; iter = iter->next ) {
|
||||
if ( iter->primary ) {
|
||||
*mon = *iter;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
// IF fail, fall back to classic mode.
|
||||
char *end = NULL;
|
||||
gint64 mon_id = g_ascii_strtoll ( config.monitor, &end, 0 );
|
||||
if ( end != config.monitor ) {
|
||||
if ( mon_id >= 0 ) {
|
||||
if ( monitor_get_dimension ( mon_id, mon ) ) {
|
||||
return TRUE;
|
||||
}
|
||||
fprintf ( stderr, "Failed to find selected monitor.\n" );
|
||||
}
|
||||
if ( config.monitor == -3 ) {
|
||||
// At mouse position.
|
||||
else if ( mon_id == -3 ) {
|
||||
if ( pointer_get ( root, &x, &y ) ) {
|
||||
monitor_dimensions ( x, y, mon );
|
||||
mon->x = x;
|
||||
mon->y = y;
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
// Focused monitor
|
||||
else if ( mon_id == -1 ) {
|
||||
// Get the current desktop.
|
||||
unsigned int current_desktop = 0;
|
||||
if ( config.monitor == -1 && xcb_ewmh_get_current_desktop_reply ( &xcb->ewmh,
|
||||
xcb_ewmh_get_current_desktop ( &xcb->ewmh, xcb->screen_nbr ),
|
||||
¤t_desktop, NULL ) ) {
|
||||
xcb_get_property_cookie_t gcdc;
|
||||
gcdc = xcb_ewmh_get_current_desktop ( &xcb->ewmh, xcb->screen_nbr );
|
||||
if ( xcb_ewmh_get_current_desktop_reply ( &xcb->ewmh, gcdc, ¤t_desktop, NULL ) ) {
|
||||
xcb_get_property_cookie_t c = xcb_ewmh_get_desktop_viewport ( &xcb->ewmh, xcb->screen_nbr );
|
||||
xcb_ewmh_get_desktop_viewport_reply_t vp;
|
||||
if ( xcb_ewmh_get_desktop_viewport_reply ( &xcb->ewmh, c, &vp, NULL ) ) {
|
||||
|
@ -309,15 +391,17 @@ void monitor_active ( workarea *mon )
|
|||
monitor_dimensions ( vp.desktop_viewport[current_desktop].x,
|
||||
vp.desktop_viewport[current_desktop].y, mon );
|
||||
xcb_ewmh_get_desktop_viewport_reply_wipe ( &vp );
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
xcb_ewmh_get_desktop_viewport_reply_wipe ( &vp );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if ( mon_id == -2 || mon_id == -4 ) {
|
||||
xcb_window_t active_window;
|
||||
if ( xcb_ewmh_get_active_window_reply ( &xcb->ewmh,
|
||||
xcb_ewmh_get_active_window ( &xcb->ewmh, xcb->screen_nbr ), &active_window, NULL ) ) {
|
||||
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 ) ) {
|
||||
// get geometry.
|
||||
xcb_get_geometry_cookie_t c = xcb_get_geometry ( xcb->connection, active_window );
|
||||
xcb_get_geometry_reply_t *r = xcb_get_geometry_reply ( xcb->connection, c, NULL );
|
||||
|
@ -325,7 +409,7 @@ void monitor_active ( workarea *mon )
|
|||
xcb_translate_coordinates_cookie_t ct = xcb_translate_coordinates ( xcb->connection, active_window, root, r->x, r->y );
|
||||
xcb_translate_coordinates_reply_t *t = xcb_translate_coordinates_reply ( xcb->connection, ct, NULL );
|
||||
if ( t ) {
|
||||
if ( config.monitor == -2 ) {
|
||||
if ( mon_id == -2 ) {
|
||||
// place the menu above the window
|
||||
// if some window is focused, place menu above window, else fall
|
||||
// back to selected monitor.
|
||||
|
@ -333,30 +417,32 @@ void monitor_active ( workarea *mon )
|
|||
mon->y = t->dst_y - r->y;
|
||||
mon->w = r->width;
|
||||
mon->h = r->height;
|
||||
mon->t = r->border_width;
|
||||
mon->b = r->border_width;
|
||||
mon->l = r->border_width;
|
||||
mon->r = r->border_width;
|
||||
free ( r );
|
||||
free ( t );
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
else if ( config.monitor == -4 ) {
|
||||
else if ( mon_id == -4 ) {
|
||||
monitor_dimensions ( t->dst_x, t->dst_y, mon );
|
||||
free ( r );
|
||||
free ( t );
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
free ( r );
|
||||
}
|
||||
}
|
||||
}
|
||||
// Monitor that has mouse pointer.
|
||||
else if ( mon_id == -5 ) {
|
||||
if ( pointer_get ( root, &x, &y ) ) {
|
||||
monitor_dimensions ( x, y, mon );
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// Fallback.
|
||||
monitor_dimensions ( 0, 0, mon );
|
||||
return FALSE;
|
||||
}
|
||||
int take_pointer ( xcb_window_t w )
|
||||
{
|
||||
|
@ -794,6 +880,7 @@ void xcb_stuff_wipe ( xcb_stuff *xcb )
|
|||
sn_display_unref ( xcb->sndisplay );
|
||||
xcb->sndisplay = NULL;
|
||||
}
|
||||
x11_monitors_free ();
|
||||
xcb_disconnect ( xcb->connection );
|
||||
xcb->connection = NULL;
|
||||
xcb->screen = NULL;
|
||||
|
|
|
@ -161,10 +161,10 @@ static XrmOption xrmOptions[] = {
|
|||
"Use regex matching", CONFIG_DEFAULT },
|
||||
{ xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL,
|
||||
"Tokenize input string", CONFIG_DEFAULT },
|
||||
{ xrm_Number, "monitor", { .snum = &config.monitor }, NULL,
|
||||
{ xrm_String, "monitor", { .str = &config.monitor }, NULL,
|
||||
"", CONFIG_DEFAULT },
|
||||
/* Alias for dmenu compatibility. */
|
||||
{ xrm_SNumber, "m", { .snum = &config.monitor }, NULL,
|
||||
{ xrm_String, "m", { .str = &config.monitor }, NULL,
|
||||
"Monitor id to show on", CONFIG_DEFAULT },
|
||||
{ xrm_Number, "line-margin", { .num = &config.line_margin }, NULL,
|
||||
"Margin between rows", CONFIG_DEFAULT },
|
||||
|
|
Loading…
Reference in a new issue