-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgui.c
65 lines (52 loc) · 1.64 KB
/
gui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* pngview - a standalone PNG viewer
* Copyright 2013 Vegard Edvardsen
*/
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "png.h"
void gui_display_image(png_t *png)
{
Display *display = XOpenDisplay(NULL);
int screen = DefaultScreen(display);
int black = BlackPixel(display, screen);
Window window = XCreateSimpleWindow(
display,
DefaultRootWindow(display),
0, 0,
png->width, png->height,
0,
black, black);
char title[500];
snprintf(title, 500, "%s - %dx%d - pngview",
png->name, png->width, png->height);
XStoreName(display, window, title);
XSizeHints *hints = XAllocSizeHints();
hints->flags = PMinSize | PMaxSize;
hints->min_width = hints->max_width = png->width;
hints->min_height = hints->max_height = png->height;
XSetWMNormalHints(display, window, hints);
XFree(hints);
XMapWindow(display, window);
GC gc = DefaultGC(display, screen);
Visual *visual = DefaultVisual(display, screen);
char *image_data = png_get_data(png);
XImage *image = XCreateImage(display, visual, 24, ZPixmap, 0,
image_data, png->width, png->height, 32, 0);
XSelectInput(display, window, ExposureMask);
while (1) {
XEvent event;
XNextEvent(display, &event);
switch(event.type) {
case Expose:
if (event.xexpose.count > 0) {
break;
}
XPutImage(display, window, gc, image, 0, 0, 0, 0,
png->width, png->height);
break;
}
}
XCloseDisplay(display);
}