Krolyxon
Commit 8c24034

Branches

Refs →

nsxivwindow.c

87 lines · 2.1 KB · C

1/* sxiv: window.c
2 * Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#include <stdlib.h>
20#include <stdio.h>
21
22#include <X11/Xutil.h>
23
24#include "sxiv.h"
25#include "window.h"
26
27Display *dpy;
28int scr;
29int scrw, scrh;
30GC gc;
31XColor bgcol;
32
33void 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
80void 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}