11
11
12
12
#include "config.h"
13
13
14
+ #if XINERAMA
15
+ #include <xcb/xinerama.h>
16
+ #endif
17
+
14
18
// Here be dragons
15
19
16
20
#define MAX (a ,b ) ((a > b) ? a : b)
@@ -125,12 +129,13 @@ draw_char (int x, int align, wchar_t ch)
125
129
}
126
130
127
131
void
128
- parse (char * text )
132
+ parse (char * text , int screen )
129
133
{
130
134
unsigned char * p = text ;
131
135
132
136
int pos_x = 0 ;
133
137
int align = 0 ;
138
+ bool is_screen = true;
134
139
135
140
xcb_fill_rect (clear_gc , 0 , 0 , bar_width , BAR_HEIGHT );
136
141
@@ -140,7 +145,7 @@ parse (char *text)
140
145
if (* p == '\n' )
141
146
return ;
142
147
143
- if (* p == '\\' && p ++ && * p != '\\' && strchr ("fbulcr " , * p )) {
148
+ if (* p == '\\' && p ++ && * p != '\\' && strchr ("fbuslcr " , * p )) {
144
149
switch (* p ++ ) {
145
150
case 'f' :
146
151
if (!isdigit (* p )) * p = '1' ;
@@ -154,6 +159,14 @@ parse (char *text)
154
159
if (!isdigit (* p )) * p = '0' ;
155
160
xcb_set_ud ((* p ++ )- '0' );
156
161
break ;
162
+ case 's' :
163
+ if (!isdigit (* p )) {
164
+ ++ p ;
165
+ is_screen = true;
166
+ } else {
167
+ is_screen = (screen < 0 ) || (((* p ++ ) - '0' ) == screen );
168
+ }
169
+ break ;
157
170
158
171
case 'l' :
159
172
align = ALIGN_L ;
@@ -194,7 +207,9 @@ parse (char *text)
194
207
else
195
208
xcb_set_fontset (FONT_MAIN );
196
209
197
- pos_x += draw_char (pos_x , align , t );
210
+ if (is_screen ) {
211
+ pos_x += draw_char (pos_x , align , t );
212
+ }
198
213
}
199
214
}
200
215
}
@@ -307,10 +322,11 @@ set_ewmh_atoms (xcb_window_t root)
307
322
}
308
323
309
324
void
310
- init (void )
325
+ init (int screen )
311
326
{
312
327
xcb_screen_t * scr ;
313
328
xcb_window_t root ;
329
+ int x ;
314
330
int y ;
315
331
316
332
/* Connect to X */
@@ -325,16 +341,39 @@ init (void)
325
341
root = scr -> root ;
326
342
327
343
/* where to place the window */
344
+ x = BAR_OFFSET ;
328
345
y = (bar_bottom ) ? (scr -> height_in_pixels - BAR_HEIGHT ) : 0 ;
329
346
bar_width = (BAR_WIDTH < 0 ) ? (scr -> width_in_pixels - BAR_OFFSET ) : BAR_WIDTH ;
330
347
348
+ #if XINERAMA
349
+ if (screen >= 0 ) {
350
+ xcb_xinerama_screen_info_t * xinerama_scr = NULL ;
351
+ xcb_xinerama_query_screens_cookie_t xinerama_query ;
352
+ xcb_xinerama_screen_info_iterator_t iter ;
353
+ xcb_generic_error_t * err = NULL ;
354
+ xinerama_query = xcb_xinerama_query_screens_unchecked (c );
355
+ iter = xcb_xinerama_query_screens_screen_info_iterator (xcb_xinerama_query_screens_reply (c , xinerama_query , & err ));
356
+ for (; iter .rem ; -- screen , xcb_xinerama_screen_info_next (& iter )) {
357
+ if (screen == 0 ) {
358
+ xinerama_scr = iter .data ;
359
+ break ;
360
+ }
361
+ }
362
+ if (xinerama_scr != NULL ) {
363
+ y = (bar_bottom ) ? (xinerama_scr -> y_org + xinerama_scr -> height - BAR_HEIGHT ) : 0 ;
364
+ x = xinerama_scr -> x_org + BAR_OFFSET ;
365
+ bar_width = (BAR_WIDTH < 0 ) ? (xinerama_scr -> width - BAR_OFFSET ) : BAR_WIDTH ;
366
+ }
367
+ }
368
+ #endif
369
+
331
370
/* Load the font */
332
371
if (font_load ((const char * []){ BAR_FONT }))
333
372
exit (1 );
334
373
335
374
/* Create the main window */
336
375
win = xcb_generate_id (c );
337
- xcb_create_window (c , XCB_COPY_FROM_PARENT , win , root , BAR_OFFSET , y , bar_width ,
376
+ xcb_create_window (c , XCB_COPY_FROM_PARENT , win , root , x , y , bar_width ,
338
377
BAR_HEIGHT , 0 , XCB_WINDOW_CLASS_INPUT_OUTPUT , scr -> root_visual ,
339
378
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK , (const uint32_t []){ palette [0 ], XCB_EVENT_MASK_EXPOSURE });
340
379
@@ -361,7 +400,7 @@ init (void)
361
400
/* Make the bar visible */
362
401
xcb_map_window (c , win );
363
402
/* Send a configure event. Needed to make bar work with Openbox */
364
- xcb_configure_window (c , win , XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y , (const uint32_t []){ BAR_OFFSET , y });
403
+ xcb_configure_window (c , win , XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y , (const uint32_t []){ x , y });
365
404
366
405
xcb_flush (c );
367
406
}
@@ -410,25 +449,28 @@ main (int argc, char **argv)
410
449
xcb_expose_event_t * expose_ev ;
411
450
412
451
int permanent = 0 ;
452
+ int screen = -1 ;
413
453
414
454
char ch ;
415
- while ((ch = getopt (argc , argv , "phb " )) != -1 ) {
455
+ while ((ch = getopt (argc , argv , "phbs: " )) != -1 ) {
416
456
switch (ch ) {
417
457
case 'h' :
418
458
printf ("usage: %s [-p | -h] [-b]\n"
419
459
"\t-h Show this help\n"
420
460
"\t-b Put bar at the bottom of the screen\n"
421
- "\t-p Don't close after the data ends\n" , argv [0 ]);
461
+ "\t-p Don't close after the data ends\n"
462
+ "\t-s Select screen to use\n" , argv [0 ]);
422
463
exit (0 );
423
464
case 'p' : permanent = 1 ; break ;
424
465
case 'b' : bar_bottom = 1 ; break ;
466
+ case 's' : screen = atoi (optarg ); break ;
425
467
}
426
468
}
427
469
428
470
atexit (cleanup );
429
471
signal (SIGINT , sighandle );
430
472
signal (SIGTERM , sighandle );
431
- init ();
473
+ init (screen );
432
474
433
475
/* Get the fd to Xserver */
434
476
pollin [1 ].fd = xcb_get_file_descriptor (c );
@@ -445,7 +487,7 @@ main (int argc, char **argv)
445
487
}
446
488
if (pollin [0 ].revents & POLLIN ) { /* New input, process it */
447
489
fgets (input , sizeof (input ), stdin );
448
- parse (input );
490
+ parse (input , screen );
449
491
redraw = 1 ;
450
492
}
451
493
if (pollin [1 ].revents & POLLIN ) { /* Xserver broadcasted an event */
0 commit comments