| @@ -18,17 +18,19 @@ |
| 18 | 18 | | |
| 19 | 19 | | #include <stdlib.h> |
| 20 | 20 | | #include <stdio.h> |
| 21 | + | #include <string.h> |
| 21 | 22 | | |
| 22 | 23 | | #include <X11/Xutil.h> |
| 23 | 24 | | |
| 24 | 25 | | #include "sxiv.h" |
| 25 | 26 | | #include "window.h" |
| 26 | 27 | | |
| 28 | + | GC bgc; |
| 29 | + | |
| 27 | 30 | | void win_open(win_t *win) { |
| 28 | 31 | | win_env_t *e; |
| 29 | 32 | | XClassHint *classhint; |
| 30 | 33 | | XColor bgcol; |
| 31 | | − | XGCValues gcval; |
| 32 | 34 | | |
| 33 | 35 | | if (!win) |
| 34 | 36 | | return; |
| @@ -48,6 +50,9 @@ void win_open(win_t *win) { |
| 48 | 50 | | &bgcol, &bgcol)) |
| 49 | 51 | | DIE("could not allocate color: %s", BG_COLOR); |
| 50 | 52 | | |
| 53 | + | win->bgcol = bgcol.pixel; |
| 54 | + | win->pm = 0; |
| 55 | + | |
| 51 | 56 | | win->w = WIN_WIDTH; |
| 52 | 57 | | win->h = WIN_HEIGHT; |
| 53 | 58 | | if (win->w > e->scrw) |
| @@ -66,9 +71,7 @@ void win_open(win_t *win) { |
| 66 | 71 | | XSelectInput(e->dpy, win->xwin, |
| 67 | 72 | | StructureNotifyMask | KeyPressMask); |
| 68 | 73 | | |
| 69 | | − | gcval.foreground = bgcol.pixel; |
| 70 | | − | win->bgc = XCreateGC(e->dpy, win->xwin, GCForeground, &gcval); |
| 71 | | − | win->pm = 0; |
| 74 | + | bgc = XCreateGC(e->dpy, win->xwin, 0, None); |
| 72 | 75 | | |
| 73 | 76 | | win_set_title(win, "sxiv"); |
| 74 | 77 | | |
| @@ -119,8 +122,34 @@ int win_configure(win_t *win, XConfigureEvent *c) { |
| 119 | 122 | | return changed; |
| 120 | 123 | | } |
| 121 | 124 | | |
| 125 | + | void win_toggle_fullscreen(win_t *win) { |
| 126 | + | XEvent ev; |
| 127 | + | XClientMessageEvent *cm; |
| 128 | + | |
| 129 | + | if (!win) |
| 130 | + | return; |
| 131 | + | |
| 132 | + | win->fullscreen ^= 1; |
| 133 | + | |
| 134 | + | memset(&ev, 0, sizeof(ev)); |
| 135 | + | ev.type = ClientMessage; |
| 136 | + | |
| 137 | + | cm = &ev.xclient; |
| 138 | + | cm->window = win->xwin; |
| 139 | + | cm->message_type = XInternAtom(win->env.dpy, "_NET_WM_STATE", False); |
| 140 | + | cm->format = 32; |
| 141 | + | cm->data.l[0] = win->fullscreen; |
| 142 | + | cm->data.l[1] = XInternAtom(win->env.dpy, "_NET_WM_STATE_FULLSCREEN", False); |
| 143 | + | cm->data.l[2] = XInternAtom(win->env.dpy, "_NET_WM_STATE_ABOVE", False); |
| 144 | + | cm->data.l[3] = 0; |
| 145 | + | |
| 146 | + | XSendEvent(win->env.dpy, DefaultRootWindow(win->env.dpy), False, |
| 147 | + | SubstructureNotifyMask, &ev); |
| 148 | + | } |
| 149 | + | |
| 122 | 150 | | void win_clear(win_t *win) { |
| 123 | 151 | | win_env_t *e; |
| 152 | + | XGCValues gcval; |
| 124 | 153 | | |
| 125 | 154 | | if (!win) |
| 126 | 155 | | return; |
| @@ -130,7 +159,11 @@ void win_clear(win_t *win) { |
| 130 | 159 | | if (win->pm) |
| 131 | 160 | | XFreePixmap(e->dpy, win->pm); |
| 132 | 161 | | win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth); |
| 133 | | − | XFillRectangle(e->dpy, win->pm, win->bgc, 0, 0, e->scrw, e->scrh); |
| 162 | + | |
| 163 | + | gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) : win->bgcol; |
| 164 | + | XChangeGC(e->dpy, bgc, GCForeground, &gcval); |
| 165 | + | |
| 166 | + | XFillRectangle(e->dpy, win->pm, bgc, 0, 0, e->scrw, e->scrh); |
| 134 | 167 | | } |
| 135 | 168 | | |
| 136 | 169 | | void win_draw(win_t *win) { |