Implemented fullscreen mode

This commit is contained in:
Bert 2011-01-23 16:14:41 +01:00
parent 8183b5a202
commit 2b1c0885fe
4 changed files with 46 additions and 7 deletions

1
TODO
View file

@ -2,5 +2,4 @@
- add some useful command line options - add some useful command line options
- write man page - write man page
- toggle aliasing - toggle aliasing
- fullscreen mode
- view all images in directories (recursive mode) - view all images in directories (recursive mode)

5
main.c
View file

@ -218,6 +218,11 @@ void on_keypress(XEvent *ev) {
case 'l': case 'l':
changed = img_pan(&img, &win, PAN_RIGHT); changed = img_pan(&img, &win, PAN_RIGHT);
break; break;
/* change window state */
case 'f':
win_toggle_fullscreen(&win);
break;
} }
if (changed) { if (changed) {

View file

@ -18,17 +18,19 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "sxiv.h" #include "sxiv.h"
#include "window.h" #include "window.h"
GC bgc;
void win_open(win_t *win) { void win_open(win_t *win) {
win_env_t *e; win_env_t *e;
XClassHint *classhint; XClassHint *classhint;
XColor bgcol; XColor bgcol;
XGCValues gcval;
if (!win) if (!win)
return; return;
@ -48,6 +50,9 @@ void win_open(win_t *win) {
&bgcol, &bgcol)) &bgcol, &bgcol))
DIE("could not allocate color: %s", BG_COLOR); DIE("could not allocate color: %s", BG_COLOR);
win->bgcol = bgcol.pixel;
win->pm = 0;
win->w = WIN_WIDTH; win->w = WIN_WIDTH;
win->h = WIN_HEIGHT; win->h = WIN_HEIGHT;
if (win->w > e->scrw) if (win->w > e->scrw)
@ -66,9 +71,7 @@ void win_open(win_t *win) {
XSelectInput(e->dpy, win->xwin, XSelectInput(e->dpy, win->xwin,
StructureNotifyMask | KeyPressMask); StructureNotifyMask | KeyPressMask);
gcval.foreground = bgcol.pixel; bgc = XCreateGC(e->dpy, win->xwin, 0, None);
win->bgc = XCreateGC(e->dpy, win->xwin, GCForeground, &gcval);
win->pm = 0;
win_set_title(win, "sxiv"); win_set_title(win, "sxiv");
@ -119,8 +122,34 @@ int win_configure(win_t *win, XConfigureEvent *c) {
return changed; return changed;
} }
void win_toggle_fullscreen(win_t *win) {
XEvent ev;
XClientMessageEvent *cm;
if (!win)
return;
win->fullscreen ^= 1;
memset(&ev, 0, sizeof(ev));
ev.type = ClientMessage;
cm = &ev.xclient;
cm->window = win->xwin;
cm->message_type = XInternAtom(win->env.dpy, "_NET_WM_STATE", False);
cm->format = 32;
cm->data.l[0] = win->fullscreen;
cm->data.l[1] = XInternAtom(win->env.dpy, "_NET_WM_STATE_FULLSCREEN", False);
cm->data.l[2] = XInternAtom(win->env.dpy, "_NET_WM_STATE_ABOVE", False);
cm->data.l[3] = 0;
XSendEvent(win->env.dpy, DefaultRootWindow(win->env.dpy), False,
SubstructureNotifyMask, &ev);
}
void win_clear(win_t *win) { void win_clear(win_t *win) {
win_env_t *e; win_env_t *e;
XGCValues gcval;
if (!win) if (!win)
return; return;
@ -130,7 +159,11 @@ void win_clear(win_t *win) {
if (win->pm) if (win->pm)
XFreePixmap(e->dpy, win->pm); XFreePixmap(e->dpy, win->pm);
win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth); win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth);
XFillRectangle(e->dpy, win->pm, win->bgc, 0, 0, e->scrw, e->scrh);
gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) : win->bgcol;
XChangeGC(e->dpy, bgc, GCForeground, &gcval);
XFillRectangle(e->dpy, win->pm, bgc, 0, 0, e->scrw, e->scrh);
} }
void win_draw(win_t *win) { void win_draw(win_t *win) {

View file

@ -33,7 +33,8 @@ typedef struct win_env_s {
typedef struct win_s { typedef struct win_s {
Window xwin; Window xwin;
win_env_t env; win_env_t env;
GC bgc;
unsigned long bgcol;
Pixmap pm; Pixmap pm;
int w; int w;
@ -51,6 +52,7 @@ void win_close(win_t*);
void win_set_title(win_t*, const char*); void win_set_title(win_t*, const char*);
int win_configure(win_t*, XConfigureEvent*); int win_configure(win_t*, XConfigureEvent*);
void win_toggle_fullscreen(win_t*);
void win_clear(win_t*); void win_clear(win_t*);
void win_draw(win_t*); void win_draw(win_t*);