diff --git a/display.c b/display.c index 352cd56db9f1b9e399830727f0d2d3e852475829..4d4a7125ccb55142eb11de57b4928378ef8d38ee 100644 --- a/display.c +++ b/display.c @@ -26,6 +26,7 @@ struct osd_state { // Basic characteristics of current display and screen + Display *dpy; int screen; Visual *visual; @@ -34,6 +35,8 @@ struct osd_state { int depth; int screen_width; int screen_height; + int screen_x; + int screen_y; // Our window Window win; @@ -115,7 +118,30 @@ stay_on_top(struct osd_state *osd) DBG("stay_on_top: WM does not support any known protocol\n"); } -struct osd_state *osd_new(Display *dpy) +struct osd_set osd_set_new(Display *dpy) +{ + struct osd_set set; + set.len=0; + + FILE * f = popen("xrandr | grep \\ connected","r"); + char line[1000]; + while(fscanf(f," %1000[^\n]",line)==1) + { + int width,height,x,y; + char *l = line; + while(*l && !(*l==' ')) l++; + while(*l && !('0'<=*l&&*l<='9')) l++; + if(sscanf(l,"%dx%d+%d+%d",&width,&height,&x,&y)==4) + if(set.len < OSD_MAX_SET_LEN) + { + DBG("ADD screen %dx%d on %d,%d\n",width,height,x,y); + set.state[set.len++] = osd_state_new(dpy,width,height,x,y); + } + } + return set; +} + +struct osd_state *osd_state_new(Display *dpy,int width,int height,int x,int y) { struct osd_state *osd = xmalloc(sizeof(*osd)); memset(osd, 0, sizeof(*osd)); @@ -128,8 +154,10 @@ struct osd_state *osd_new(Display *dpy) // FIXME: These can change. And what about Xinerama? osd->depth = XDefaultDepth(osd->dpy, osd->screen); - osd->screen_width = XDisplayWidth(osd->dpy, osd->screen); - osd->screen_height = XDisplayHeight(osd->dpy, osd->screen); + osd->screen_width = width; + osd->screen_height = height; + osd->screen_x = x; + osd->screen_y = y; DBG("Screen: %dx%d depth %d\n", osd->screen_width, osd->screen_height, osd->depth); int event_basep, error_basep; @@ -469,7 +497,7 @@ void osd_show(struct osd_state *osd) }; osd->win = XCreateWindow(osd->dpy, osd->root, - (osd->screen_width - osd->win_width) / 2, (osd->screen_height - osd->win_height) / 2, + (osd->screen_width - osd->win_width) / 2 + osd->screen_x, (osd->screen_height - osd->win_height) / 2 + osd->screen_y, osd->win_width, osd->win_height, 0, osd->depth, diff --git a/display.h b/display.h index fb21c248e54a870bc08ccd8f6288a19faaf42a01..379451df9b1a59298f4034ae1b6c97783abb710b 100644 --- a/display.h +++ b/display.h @@ -38,7 +38,15 @@ struct osd_line { int log; }; -struct osd_state *osd_new(Display *dpy); +#define ALL_OSD_SET(set) for(int ALL_OSD_SET_i=0;ALL_OSD_SET_i<set.len;ALL_OSD_SET_i++) set->state[ALL_OSD_SET_i] +#define OSD_MAX_SET_LEN 10 +struct osd_set { + struct osd_state* state[OSD_MAX_SET_LEN]; + int len; +}; + +struct osd_state *osd_state_new(Display *dpy,int width,int height,int x,int y); +struct osd_set osd_set_new(Display *dpy); void osd_free(struct osd_state *osd); void osd_set_font(struct osd_state *osd, char *font_name, double line_spacing); struct osd_line *osd_add_line(struct osd_state *osd, enum osd_line_type type); diff --git a/osdd.c b/osdd.c index 3dd92e43d35f1cf8a9b05fcda89e73e9089b26a8..0f5723bc9bfa650772d8dde0573c3ccacda79a31 100644 --- a/osdd.c +++ b/osdd.c @@ -18,7 +18,8 @@ #include "util.h" #include "display.h" -static struct osd_state *osd; +static struct osd_set osd; +#define FOREACHOSD for(int i=0;i<osd.len;i++) static timestamp_t now; @@ -160,21 +161,22 @@ display_msg(struct msg *msg) } DBG("\t%s:%s\n", key, val); - struct osd_line *l = NULL; + struct osd_line *l[OSD_MAX_SET_LEN]; + FOREACHOSD l[i]=0; if (!key[0]) { - l = osd_add_line(osd, OSD_TYPE_TEXT); - sprintf(l->u.text, "%.*s", OSD_MAX_LINE_LEN, val); + FOREACHOSD l[i] = osd_add_line(osd.state[i], OSD_TYPE_TEXT); + FOREACHOSD sprintf(l[i]->u.text, "%.*s", OSD_MAX_LINE_LEN, val); } else if (!strcmp(key, "percentage") || !strcmp(key, "percent")) { - l = osd_add_line(osd, OSD_TYPE_PERCENTAGE); - l->u.percent = atoi(val); + FOREACHOSD l[i] = osd_add_line(osd.state[i], OSD_TYPE_PERCENTAGE); + FOREACHOSD l[i]->u.percent = atoi(val); } else if (!strcmp(key, "slider")) { - l = osd_add_line(osd, OSD_TYPE_SLIDER); - l->u.percent = atoi(val); + FOREACHOSD l[i] = osd_add_line(osd.state[i], OSD_TYPE_SLIDER); + FOREACHOSD l[i]->u.percent = atoi(val); } else if (!strcmp(key, "duration")) msg->max_light = now + atoi(val); @@ -188,21 +190,21 @@ display_msg(struct msg *msg) outline_color = val; else if (!strcmp(key, "outline-width")) outline_width = atoi(val); - if (l) + FOREACHOSD if (l[i]) { num_l++; - l->fg_color = fg_color; - l->outline_color = outline_color; - l->outline_width = outline_width; - l->log = log; + l[i]->fg_color = fg_color; + l[i]->outline_color = outline_color; + l[i]->outline_width = outline_width; + l[i]->log = i?0:log; } line = nl; } - if(!num_l) + if(!num_l) FOREACHOSD { - struct osd_line *l = osd_add_line(osd,OSD_TYPE_TEXT); + struct osd_line *l = osd_add_line(osd.state[i],OSD_TYPE_TEXT); l->u.text[0]=0; l->fg_color = fg_color; l->outline_color = outline_color; @@ -213,7 +215,7 @@ display_msg(struct msg *msg) if (msg->min_light > msg->max_light) msg->min_light = msg->max_light; - osd_show(osd); + FOREACHOSD osd_show(osd.state[i]); } static void @@ -258,7 +260,7 @@ static void hide_msg(struct msg *msg) { DBG("## Hiding message\n"); - osd_clear(osd); + FOREACHOSD osd_clear(osd.state[i]); free(msg); } @@ -397,8 +399,8 @@ main(int argc, char **argv) XFlush(dpy); } - osd = osd_new(dpy); - osd_set_font(osd, font_name, line_spacing); + osd = osd_set_new(dpy); + FOREACHOSD osd_set_font(osd.state[i], font_name, line_spacing); struct pollfd pfd = { .fd = ConnectionNumber(dpy), @@ -440,7 +442,7 @@ main(int argc, char **argv) { XEvent ev; XNextEvent(dpy, &ev); - if (osd_handle_event(osd, &ev)) + FOREACHOSD if (osd_handle_event(osd.state[i], &ev)) continue; if (ev.type != PropertyNotify) continue;