Krolyxon
Commit 2b1c088

Branches

Refs →

nsxiv2b1c088

Implemented fullscreen mode

Author
Bert
Date
2011-01-23 16:14 +0100
Parent
8183b5a
Commit
2b1c0885fe53b95455ae650762651c69ae1a227d

+46 −7

4 files changed

  1. M TODO +0 −1
  2. M main.c +5 −0
  3. M window.c +38 −5
  4. M window.h +3 −1
M TODO View
@@ -2,5 +2,4 @@
22 - add some useful command line options
33 - write man page
44 - toggle aliasing
5−- fullscreen mode
65 - view all images in directories (recursive mode)
M main.c View
@@ -218,6 +218,11 @@ void on_keypress(XEvent *ev) {
218218 case 'l':
219219 changed = img_pan(&img, &win, PAN_RIGHT);
220220 break;
221+
222+ /* change window state */
223+ case 'f':
224+ win_toggle_fullscreen(&win);
225+ break;
221226 }
222227
223228 if (changed) {
M window.c View
@@ -18,17 +18,19 @@
1818
1919 #include <stdlib.h>
2020 #include <stdio.h>
21+#include <string.h>
2122
2223 #include <X11/Xutil.h>
2324
2425 #include "sxiv.h"
2526 #include "window.h"
2627
28+GC bgc;
29+
2730 void win_open(win_t *win) {
2831 win_env_t *e;
2932 XClassHint *classhint;
3033 XColor bgcol;
31− XGCValues gcval;
3234
3335 if (!win)
3436 return;
@@ -48,6 +50,9 @@ void win_open(win_t *win) {
4850 &bgcol, &bgcol))
4951 DIE("could not allocate color: %s", BG_COLOR);
5052
53+ win->bgcol = bgcol.pixel;
54+ win->pm = 0;
55+
5156 win->w = WIN_WIDTH;
5257 win->h = WIN_HEIGHT;
5358 if (win->w > e->scrw)
@@ -66,9 +71,7 @@ void win_open(win_t *win) {
6671 XSelectInput(e->dpy, win->xwin,
6772 StructureNotifyMask | KeyPressMask);
6873
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);
7275
7376 win_set_title(win, "sxiv");
7477
@@ -119,8 +122,34 @@ int win_configure(win_t *win, XConfigureEvent *c) {
119122 return changed;
120123 }
121124
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+
122150 void win_clear(win_t *win) {
123151 win_env_t *e;
152+ XGCValues gcval;
124153
125154 if (!win)
126155 return;
@@ -130,7 +159,11 @@ void win_clear(win_t *win) {
130159 if (win->pm)
131160 XFreePixmap(e->dpy, win->pm);
132161 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);
134167 }
135168
136169 void win_draw(win_t *win) {
M window.h View
@@ -33,7 +33,8 @@ typedef struct win_env_s {
3333 typedef struct win_s {
3434 Window xwin;
3535 win_env_t env;
36− GC bgc;
36+
37+ unsigned long bgcol;
3738 Pixmap pm;
3839
3940 int w;
@@ -51,6 +52,7 @@ void win_close(win_t*);
5152 void win_set_title(win_t*, const char*);
5253
5354 int win_configure(win_t*, XConfigureEvent*);
55+void win_toggle_fullscreen(win_t*);
5456
5557 void win_clear(win_t*);
5658 void win_draw(win_t*);