Skip to content
Snippets Groups Projects
Commit 7f62214e authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Add support for multiple outputs (v2)

parent 1e8f3e84
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -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);
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment