screen_info struct

put all variables that contain information about
the current screen in one struct to keep things clean.
This commit is contained in:
Sascha Kruse 2011-09-10 23:30:50 +02:00
parent 939d1f980b
commit fcdbf8ec0d

54
dunst.c
View File

@ -25,6 +25,13 @@ typedef struct _msg_queue_t {
time_t start; time_t start;
} msg_queue_t; } msg_queue_t;
typedef struct _screen_info {
int scr;
int x;
int y;
int h;
int w;
} screen_info;
/* global variables */ /* global variables */
static int expand = True; static int expand = True;
@ -44,13 +51,8 @@ static int listen_to_dbus = True;
static int visible = False; static int visible = False;
static KeySym key = NoSymbol; static KeySym key = NoSymbol;
static KeySym mask = 0; static KeySym mask = 0;
static int screen = -1; static screen_info scr;
static int screen_x = 0; static int message_h;
static int screen_y = 0;
static int screen_h = 0;
static int screen_w = 0;
static int message_h = 0;
/* list functions */ /* list functions */
msg_queue_t *append(msg_queue_t *queue, char *msg); msg_queue_t *append(msg_queue_t *queue, char *msg);
@ -107,16 +109,16 @@ drawmsg(const char *msg) {
dc->x = 0; dc->x = 0;
dc->y = 0; dc->y = 0;
dc->h = 0; dc->h = 0;
y = topbar ? 0 : screen_h - message_h; y = topbar ? 0 : scr.h - message_h;
if(expand) { if(expand) {
width = screen_w; width = scr.w;
} else { } else {
width = textw(dc, msg); width = textw(dc, msg);
} }
if(right) { if(right) {
x = screen_x + (screen_w - width); x = scr.x + (scr.w - width);
} else { } else {
x = screen_x; x = scr.x;
} }
resizedc(dc, width, message_h); resizedc(dc, width, message_h);
XResizeWindow(dc->dpy, win, width, message_h); XResizeWindow(dc->dpy, win, width, message_h);
@ -135,7 +137,7 @@ handleXEvents(void) {
switch(ev.type) { switch(ev.type) {
case Expose: case Expose:
if(ev.xexpose.count == 0) if(ev.xexpose.count == 0)
mapdc(dc, win, screen_w, message_h); mapdc(dc, win, scr.w, message_h);
break; break;
case SelectionNotify: case SelectionNotify:
if(ev.xselection.property == utf8) if(ev.xselection.property == utf8)
@ -206,8 +208,8 @@ setup(void) {
int n; int n;
XineramaScreenInfo *info; XineramaScreenInfo *info;
#endif #endif
if(screen < 0) { if(scr.scr < 0) {
screen = DefaultScreen(dc->dpy); scr.scr = DefaultScreen(dc->dpy);
} }
root = RootWindow(dc->dpy, DefaultScreen(dc->dpy)); root = RootWindow(dc->dpy, DefaultScreen(dc->dpy));
@ -220,29 +222,29 @@ setup(void) {
message_h = dc->font.height + 2; message_h = dc->font.height + 2;
#ifdef XINERAMA #ifdef XINERAMA
if((info = XineramaQueryScreens(dc->dpy, &n))) { if((info = XineramaQueryScreens(dc->dpy, &n))) {
if(screen >= n) { if(scr.scr >= n) {
fprintf(stderr, "Monitor %d not found\n", screen); fprintf(stderr, "Monitor %d not found\n", scr.scr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
screen_x = info[screen].x_org; scr.x = info[scr.scr].x_org;
screen_y = info[screen].y_org; scr.y = info[scr.scr].y_org;
screen_h = info[screen].height; scr.h = info[scr.scr].height;
screen_w = info[screen].width; scr.w = info[scr.scr].width;
XFree(info); XFree(info);
} }
else else
#endif #endif
{ {
screen_x = 0; scr.x = 0;
screen_y = 0; scr.y = 0;
screen_w = DisplayWidth(dc->dpy, screen); scr.w = DisplayWidth(dc->dpy, scr.scr);
screen_h = DisplayHeight(dc->dpy, screen); scr.h = DisplayHeight(dc->dpy, scr.scr);
} }
/* menu window */ /* menu window */
wa.override_redirect = True; wa.override_redirect = True;
wa.background_pixmap = ParentRelative; wa.background_pixmap = ParentRelative;
wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask | ButtonPressMask; wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask | ButtonPressMask;
win = XCreateWindow(dc->dpy, root, screen_x, screen_y, screen_w, message_h, 0, win = XCreateWindow(dc->dpy, root, scr.x, scr.y, scr.w, message_h, 0,
DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)), CopyFromParent, DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)), CopyFromParent,
DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)), DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
@ -316,7 +318,7 @@ main(int argc, char *argv[]) {
listen_to_dbus = False; listen_to_dbus = False;
} }
else if(!strcmp(argv[i], "-mon")) { else if(!strcmp(argv[i], "-mon")) {
screen = atoi(argv[++i]); scr.scr = atoi(argv[++i]);
} }
else if(!strcmp(argv[i], "-key")) { else if(!strcmp(argv[i], "-key")) {
key = XStringToKeysym(argv[i+1]); key = XStringToKeysym(argv[i+1]);