| @@ -24,78 +24,71 @@ |
| 24 | 24 | | #include "sxiv.h" |
| 25 | 25 | | #include "window.h" |
| 26 | 26 | | |
| 27 | | − | Display *dpy; |
| 28 | | − | int scr; |
| 29 | | − | int scrw, scrh; |
| 30 | | − | Visual *vis; |
| 31 | | − | Colormap cmap; |
| 32 | | − | int depth; |
| 33 | | − | GC gc; |
| 34 | | − | XColor bgcol; |
| 35 | | − | |
| 36 | 27 | | void win_open(win_t *win) { |
| 28 | + | win_env_t *e; |
| 37 | 29 | | XClassHint *classhint; |
| 30 | + | XColor bgcol; |
| 38 | 31 | | XSetWindowAttributes attr; |
| 39 | 32 | | unsigned long mask; |
| 40 | 33 | | |
| 41 | 34 | | if (!win) |
| 42 | 35 | | return; |
| 36 | + | |
| 37 | + | e = &win->env; |
| 43 | 38 | | |
| 44 | | − | if (!(dpy = XOpenDisplay(NULL))) |
| 39 | + | if (!(e->dpy = XOpenDisplay(NULL))) |
| 45 | 40 | | FATAL("could not open display"); |
| 46 | 41 | | |
| 47 | | − | scr = DefaultScreen(dpy); |
| 48 | | − | scrw = DisplayWidth(dpy, scr); |
| 49 | | − | scrh = DisplayHeight(dpy, scr); |
| 42 | + | e->scr = DefaultScreen(e->dpy); |
| 43 | + | e->scrw = DisplayWidth(e->dpy, e->scr); |
| 44 | + | e->scrh = DisplayHeight(e->dpy, e->scr); |
| 50 | 45 | | |
| 51 | | − | vis = DefaultVisual(dpy, scr); |
| 52 | | − | cmap = DefaultColormap(dpy, scr); |
| 53 | | − | depth = DefaultDepth(dpy, scr); |
| 46 | + | e->vis = DefaultVisual(e->dpy, e->scr); |
| 47 | + | e->cmap = DefaultColormap(e->dpy, e->scr); |
| 48 | + | e->depth = DefaultDepth(e->dpy, e->scr); |
| 54 | 49 | | |
| 55 | | − | if (!XAllocNamedColor(dpy, DefaultColormap(dpy, scr), BG_COLOR, |
| 56 | | − | &bgcol, &bgcol)) |
| 50 | + | if (!XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR, |
| 51 | + | &bgcol, &bgcol)) |
| 57 | 52 | | FATAL("could not allocate color: %s", BG_COLOR); |
| 58 | 53 | | |
| 59 | | − | if (win->w > scrw) |
| 60 | | − | win->w = scrw; |
| 61 | | − | if (win->h > scrh) |
| 62 | | − | win->h = scrh; |
| 63 | | − | win->x = (scrw - win->w) / 2; |
| 64 | | − | win->y = (scrh - win->h) / 2; |
| 54 | + | if (win->w > e->scrw) |
| 55 | + | win->w = e->scrw; |
| 56 | + | if (win->h > e->scrh) |
| 57 | + | win->h = e->scrh; |
| 58 | + | win->x = (e->scrw - win->w) / 2; |
| 59 | + | win->y = (e->scrh - win->h) / 2; |
| 65 | 60 | | |
| 66 | 61 | | attr.backing_store = NotUseful; |
| 67 | 62 | | attr.background_pixel = bgcol.pixel; |
| 68 | 63 | | attr.save_under = False; |
| 69 | 64 | | mask = CWBackingStore | CWBackPixel | CWSaveUnder; |
| 70 | 65 | | |
| 71 | | − | win->xwin = XCreateWindow(dpy, RootWindow(dpy, scr), win->x, win->y, |
| 72 | | − | win->w, win->h, 0, depth, InputOutput, vis, mask, &attr); |
| 66 | + | win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), |
| 67 | + | win->x, win->y, win->w, win->h, 0, |
| 68 | + | e->depth, InputOutput, e->vis, mask, &attr); |
| 73 | 69 | | if (win->xwin == None) |
| 74 | 70 | | FATAL("could not create window"); |
| 75 | 71 | | |
| 76 | | − | XSelectInput(dpy, win->xwin, |
| 77 | | − | StructureNotifyMask | ExposureMask | KeyPressMask); |
| 78 | | − | |
| 79 | | − | gc = XCreateGC(dpy, win->xwin, 0, NULL); |
| 72 | + | XSelectInput(e->dpy, win->xwin, |
| 73 | + | StructureNotifyMask | ExposureMask | KeyPressMask); |
| 80 | 74 | | |
| 81 | 75 | | if ((classhint = XAllocClassHint())) { |
| 82 | 76 | | classhint->res_name = "sxvi"; |
| 83 | 77 | | classhint->res_class = "sxvi"; |
| 84 | | − | XSetClassHint(dpy, win->xwin, classhint); |
| 78 | + | XSetClassHint(e->dpy, win->xwin, classhint); |
| 85 | 79 | | XFree(classhint); |
| 86 | 80 | | } |
| 87 | 81 | | |
| 88 | | − | XMapWindow(dpy, win->xwin); |
| 89 | | − | XFlush(dpy); |
| 82 | + | XMapWindow(e->dpy, win->xwin); |
| 83 | + | XFlush(e->dpy); |
| 90 | 84 | | } |
| 91 | 85 | | |
| 92 | 86 | | void win_close(win_t *win) { |
| 93 | 87 | | if (!win) |
| 94 | 88 | | return; |
| 95 | 89 | | |
| 96 | | − | XDestroyWindow(dpy, win->xwin); |
| 97 | | − | XFreeGC(dpy, gc); |
| 98 | | − | XCloseDisplay(dpy); |
| 90 | + | XDestroyWindow(win->env.dpy, win->xwin); |
| 91 | + | XCloseDisplay(win->env.dpy); |
| 99 | 92 | | } |
| 100 | 93 | | |
| 101 | 94 | | int win_configure(win_t *win, XConfigureEvent *cev) { |
| @@ -105,7 +98,7 @@ int win_configure(win_t *win, XConfigureEvent *cev) { |
| 105 | 98 | | return 0; |
| 106 | 99 | | |
| 107 | 100 | | changed = win->x != cev->x || win->y != cev->y || |
| 108 | | − | win->w != cev->width || win->h != cev->height; |
| 101 | + | win->w != cev->width || win->h != cev->height; |
| 109 | 102 | | win->x = cev->x; |
| 110 | 103 | | win->y = cev->y; |
| 111 | 104 | | win->w = cev->width; |