Krolyxon
Commit 49a69a3

Branches

Refs →

nsxiv49a69a3

Added win_open & win_close

Author
Bert
Date
2011-01-17 16:42 +0100
Parent
bbe7ae0
Commit
49a69a357bee345148a3d26d166121a6eaf4011c

+75 −0

2 files changed

  1. M window.c +66 −0
  2. M window.h +9 −0
M window.c View
@@ -16,6 +16,72 @@
1616 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717 */
1818
19+#include <stdlib.h>
20+#include <stdio.h>
21+
22+#include <X11/Xutil.h>
23+
1924 #include "sxiv.h"
2025 #include "window.h"
2126
27+Display *dpy;
28+int scr;
29+int scrw, scrh;
30+GC gc;
31+XColor bgcol;
32+
33+void win_open(win_t *win) {
34+ XClassHint *classhint;
35+
36+ if (win == NULL)
37+ return;
38+
39+ if (!(dpy = XOpenDisplay(NULL)))
40+ FATAL("could not open display");
41+
42+ scr = DefaultScreen(dpy);
43+ scrw = DisplayWidth(dpy, scr);
44+ scrh = DisplayHeight(dpy, scr);
45+
46+ bgcol.red = 0x7000;
47+ bgcol.green = 0x7000;
48+ bgcol.blue = 0x7000;
49+ XAllocColor(dpy, DefaultColormap(dpy, scr), &bgcol);
50+
51+ if (win->w > scrw)
52+ win->w = scrw;
53+ if (win->h > scrh)
54+ win->h = scrh;
55+ win->x = (scrw - win->w) / 2;
56+ win->y = (scrh - win->h) / 2;
57+
58+ win->xwin = XCreateWindow(dpy, RootWindow(dpy, scr),
59+ win->x, win->y, win->w, win->h, 0, DefaultDepth(dpy, scr), InputOutput,
60+ DefaultVisual(dpy, scr), 0, NULL);
61+ if (win->xwin == None)
62+ FATAL("could not create window");
63+
64+ XSelectInput(dpy, win->xwin,
65+ StructureNotifyMask | ExposureMask | KeyPressMask);
66+
67+ gc = XCreateGC(dpy, win->xwin, 0, NULL);
68+
69+ if ((classhint = XAllocClassHint())) {
70+ classhint->res_name = "sxvi";
71+ classhint->res_class = "sxvi";
72+ XSetClassHint(dpy, win->xwin, classhint);
73+ XFree(classhint);
74+ }
75+
76+ XMapWindow(dpy, win->xwin);
77+ XFlush(dpy);
78+}
79+
80+void win_close(win_t *win) {
81+ if (win == NULL)
82+ return;
83+
84+ XDestroyWindow(dpy, win->xwin);
85+ XFreeGC(dpy, gc);
86+ XCloseDisplay(dpy);
87+}
M window.h View
@@ -19,12 +19,21 @@
1919 #ifndef WINDOW_H
2020 #define WINDOW_H
2121
22+#include <X11/Xlib.h>
23+
2224 typedef struct win_s {
25+ Window xwin;
26+
2327 int w;
2428 int h;
2529 int x;
2630 int y;
31+
2732 int bw;
33+ int fullscreen;
2834 } win_t;
2935
36+void win_open(win_t *win);
37+void win_close(win_t *win);
38+
3039 #endif /* WINDOW_H */