get rid of global variable scr

This commit is contained in:
Sascha Kruse 2013-02-21 00:28:53 +00:00
parent cb0b276998
commit 6f5ef3f3a2

50
dunst.c
View File

@ -77,7 +77,6 @@ static Atom utf8;
static DC *dc; static DC *dc;
static Window win; static Window win;
static bool visible = false; static bool visible = false;
static screen_info scr;
static dimension_t geometry; static dimension_t geometry;
static XScreenSaverInfo *screensaver_info; static XScreenSaverInfo *screensaver_info;
static int font_h; static int font_h;
@ -134,7 +133,7 @@ static int x_shortcut_tear_down_error_handler(void);
/* X misc */ /* X misc */
void x_handle_click(XEvent ev); void x_handle_click(XEvent ev);
void x_screen_update_info(); void x_screen_info(screen_info *scr);
bool x_is_idle(void); bool x_is_idle(void);
void x_setup(void); void x_setup(void);
@ -1011,7 +1010,7 @@ Window get_focused_window(void)
int select_screen(XineramaScreenInfo * info, int info_len) int select_screen(XineramaScreenInfo * info, int info_len)
{ // {{{ { // {{{
if (f_mode == FOLLOW_NONE) { if (f_mode == FOLLOW_NONE) {
return scr.scr; return monitor >= 0 ? monitor : XDefaultScreen(dc->dpy);
} else { } else {
int x, y; int x, y;
@ -1034,7 +1033,7 @@ int select_screen(XineramaScreenInfo * info, int info_len)
if (focused == 0) { if (focused == 0) {
/* something went wrong. Fallback to default */ /* something went wrong. Fallback to default */
return scr.scr; return monitor >= 0 ? monitor : XDefaultScreen(dc->dpy);
} }
Window child_return; Window child_return;
@ -1051,7 +1050,7 @@ int select_screen(XineramaScreenInfo * info, int info_len)
} }
/* something seems to be wrong. Fallback to default */ /* something seems to be wrong. Fallback to default */
return scr.scr; return monitor >= 0 ? monitor : XDefaultScreen(dc->dpy);
} }
} }
// }}} // }}}
@ -1061,7 +1060,7 @@ int select_screen(XineramaScreenInfo * info, int info_len)
* Update the information about the monitor * Update the information about the monitor
* geometry. * geometry.
*/ */
void x_screen_update_info() void x_screen_info(screen_info *scr)
{ // {{{ { // {{{
#ifdef XINERAMA #ifdef XINERAMA
int n; int n;
@ -1072,18 +1071,25 @@ void x_screen_update_info()
/* invalid monitor, fallback to default */ /* invalid monitor, fallback to default */
screen = 0; screen = 0;
} }
scr.dim.x = info[screen].x_org; scr->dim.x = info[screen].x_org;
scr.dim.y = info[screen].y_org; scr->dim.y = info[screen].y_org;
scr.dim.h = info[screen].height; scr->dim.h = info[screen].height;
scr.dim.w = info[screen].width; scr->dim.w = info[screen].width;
XFree(info); XFree(info);
} else } else
#endif #endif
{ {
scr.dim.x = 0; scr->dim.x = 0;
scr.dim.y = 0; scr->dim.y = 0;
scr.dim.w = DisplayWidth(dc->dpy, scr.scr);
scr.dim.h = DisplayHeight(dc->dpy, scr.scr); int screen;
if (monitor >= 0)
screen = monitor;
else
screen = DefaultScreen(dc->dpy);
scr->dim.w = DisplayWidth(dc->dpy, screen);
scr->dim.h = DisplayHeight(dc->dpy, screen);
} }
} }
// }}} // }}}
@ -1149,10 +1155,6 @@ void x_setup(void)
screensaver_info = XScreenSaverAllocInfo(); screensaver_info = XScreenSaverAllocInfo();
scr.scr = monitor;
if (scr.scr < 0) {
scr.scr = DefaultScreen(dc->dpy);
}
x_win_setup(); x_win_setup();
x_shortcut_grab(&history_ks); x_shortcut_grab(&history_ks);
@ -1332,6 +1334,8 @@ unsigned long calculate_foreground_color(unsigned long source_color)
int calculate_width(void) int calculate_width(void)
{ // {{{ { // {{{
screen_info scr;
x_screen_info(&scr);
if (geometry.mask & WidthValue && geometry.w == 0) { if (geometry.mask & WidthValue && geometry.w == 0) {
/* dynamic width */ /* dynamic width */
return 0; return 0;
@ -1353,6 +1357,8 @@ void move_and_map(int width, int height)
{ // {{{ { // {{{
int x,y; int x,y;
screen_info scr;
x_screen_info(&scr);
/* calculate window position */ /* calculate window position */
if (geometry.mask & XNegative) { if (geometry.mask & XNegative) {
x = (scr.dim.x + (scr.dim.w - width)) + geometry.x; x = (scr.dim.x + (scr.dim.w - width)) + geometry.x;
@ -1436,8 +1442,9 @@ void free_render_texts(GSList *texts) {
void x_win_draw(void) void x_win_draw(void)
{ // {{{ { // {{{
x_screen_update_info();
int outer_width = calculate_width(); int outer_width = calculate_width();
screen_info scr;
x_screen_info(&scr);
line_height = MAX(line_height, font_h); line_height = MAX(line_height, font_h);
@ -1570,13 +1577,15 @@ void x_win_setup(void)
root = RootWindow(dc->dpy, DefaultScreen(dc->dpy)); root = RootWindow(dc->dpy, DefaultScreen(dc->dpy));
utf8 = XInternAtom(dc->dpy, "UTF8_STRING", false); utf8 = XInternAtom(dc->dpy, "UTF8_STRING", false);
font_h = dc->font.height + FONT_HEIGHT_BORDER; font_h = dc->font.height + FONT_HEIGHT_BORDER;
x_screen_update_info();
wa.override_redirect = true; wa.override_redirect = true;
wa.background_pixmap = ParentRelative; wa.background_pixmap = ParentRelative;
wa.event_mask = wa.event_mask =
ExposureMask | KeyPressMask | VisibilityChangeMask | ExposureMask | KeyPressMask | VisibilityChangeMask |
ButtonPressMask; ButtonPressMask;
screen_info scr;
x_screen_info(&scr);
win = win =
XCreateWindow(dc->dpy, root, scr.dim.x, scr.dim.y, scr.dim.w, XCreateWindow(dc->dpy, root, scr.dim.x, scr.dim.y, scr.dim.w,
font_h, 0, DefaultDepth(dc->dpy, font_h, 0, DefaultDepth(dc->dpy,
@ -1611,7 +1620,6 @@ void x_win_show(void)
fprintf(stderr, "Unable to grab mouse button(s)\n"); fprintf(stderr, "Unable to grab mouse button(s)\n");
} }
x_screen_update_info();
XMapRaised(dc->dpy, win); XMapRaised(dc->dpy, win);
visible = true; visible = true;
} }