commit 86c105f
Devine Lu Linvega
·
2025-07-19 17:21:23 +0000 UTC
parent a18193a
Fixed crash with ximage
2 files changed,
+61,
-60
M
makefile
M
makefile
+5,
-6
1@@ -3,11 +3,9 @@ DEBUG_flags=-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragma
2
3 PREFIX=${HOME}/.local
4
5-.PHONY: all debug run test install uninstall format clean grab archive
6+.PHONY: run test debug install uninstall format clean grab archive
7
8-all: bin/uxncli bin/uxn11
9-
10-run: all bin/mouse.rom
11+run: bin/uxncli bin/uxn11 bin/mouse.rom
12 @ bin/uxn11 bin/mouse.rom
13
14 cli: bin/uxncli-debug bin/console.rom
15@@ -15,7 +13,7 @@ cli: bin/uxncli-debug bin/console.rom
16 bin/uxncli-debug -v
17 @ bin/uxncli-debug bin/console.rom "foo bar" baz
18
19-gui: all bin/uxn11-debug bin/screen.rom
20+gui: bin/uxncli bin/uxn11 bin/uxn11-debug bin/screen.rom
21 bin/uxn11-debug
22 bin/uxn11-debug -v
23 bin/uxn11-debug bin/screen.rom
24@@ -29,6 +27,7 @@ controller: bin/uxn11-debug bin/controller.rom
25 test: bin/uxncli-debug bin/uxn11-debug tests
26 bin/uxncli-debug bin/test_opcodes.rom
27 bin/uxncli-debug bin/test_system_exp.rom
28+ bin/uxn11-debug bin/test_opcodes.rom
29
30 format:
31 @ clang-format -i src/uxncli.c src/uxn11.c
32@@ -45,7 +44,7 @@ archive:
33 clean:
34 @ rm -fr bin
35
36-install: all
37+install: bin/uxncli bin/uxn11
38 @ mkdir -p ${PREFIX}/bin
39 @ cp bin/uxn11 bin/uxncli ${PREFIX}/bin
40 @ mkdir -p ${PREFIX}/share/man/man7
+56,
-54
1@@ -1074,6 +1074,56 @@ get_button(KeySym sym)
2 return 0x00;
3 }
4
5+static void
6+display_hidecursor(void)
7+{
8+ XColor black = {0};
9+ char empty[] = {0};
10+ Pixmap bitmap = XCreateBitmapFromData(display, window, empty, 1, 1);
11+ Cursor blank = XCreatePixmapCursor(display, bitmap, bitmap, &black, &black, 0, 0);
12+ XDefineCursor(display, window, blank);
13+ XFreeCursor(display, blank);
14+ XFreePixmap(display, bitmap);
15+}
16+
17+static void
18+display_floating(Display *dpy, Window win)
19+{
20+ Atom wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
21+ Atom wmType = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
22+ Atom wmDialog = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
23+ XSetWMProtocols(display, window, &wmDelete, 1);
24+ XChangeProperty(dpy, win, wmType, 4, 32, PropModeReplace, (Uint8 *)&wmDialog, 1);
25+}
26+
27+static unsigned int
28+display_init(void)
29+{
30+ Screen *screen;
31+ Visual *visual;
32+ XClassHint class = {"uxn11", "Uxn"};
33+ int screen_width, screen_height;
34+ /* start display */
35+ display = XOpenDisplay(NULL);
36+ if(!display)
37+ return !fprintf(stderr, "Display: failed\n");
38+ /* start window */
39+ visual = DefaultVisual(display, 0);
40+ if(visual->class != TrueColor)
41+ return !fprintf(stderr, "Display: True-color visual failed\n");
42+ /* center */
43+ screen = ScreenOfDisplay(display, 0);
44+ screen_width = screen->width, screen_height = screen->height;
45+ window = XCreateSimpleWindow(display, RootWindow(display, 0), screen_width / 2 - uxn_screen.width / 2, screen_height / 2 - uxn_screen.height / 2, uxn_screen.width, uxn_screen.height, 1, 0, 0);
46+ display_hidecursor();
47+ display_floating(display, window);
48+ XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask | LeaveWindowMask);
49+ XStoreName(display, window, "uxn11");
50+ XSetClassHint(display, window, &class);
51+ XMapWindow(display, window);
52+ return 1;
53+}
54+
55 static void
56 emu_event(void)
57 {
58@@ -1129,62 +1179,12 @@ emu_event(void)
59 }
60
61 static void
62-display_hidecursor(void)
63-{
64- XColor black = {0};
65- char empty[] = {0};
66- Pixmap bitmap = XCreateBitmapFromData(display, window, empty, 1, 1);
67- Cursor blank = XCreatePixmapCursor(display, bitmap, bitmap, &black, &black, 0, 0);
68- XDefineCursor(display, window, blank);
69- XFreeCursor(display, blank);
70- XFreePixmap(display, bitmap);
71-}
72-
73-static void
74-display_floating(Display *dpy, Window win)
75-{
76- Atom wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
77- Atom wmType = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
78- Atom wmDialog = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
79- XSetWMProtocols(display, window, &wmDelete, 1);
80- XChangeProperty(dpy, win, wmType, 4, 32, PropModeReplace, (Uint8 *)&wmDialog, 1);
81-}
82-
83-static unsigned int
84-display_init(void)
85-{
86- Screen *screen;
87- Visual *visual;
88- XClassHint class = {"uxn11", "Uxn"};
89- int screen_width, screen_height;
90- /* start display */
91- display = XOpenDisplay(NULL);
92- if(!display)
93- return !fprintf(stderr, "Display: failed\n");
94- /* start window */
95- visual = DefaultVisual(display, 0);
96- if(visual->class != TrueColor)
97- return !fprintf(stderr, "Display: True-color visual failed\n");
98- /* center */
99- screen = ScreenOfDisplay(display, 0);
100- screen_width = screen->width, screen_height = screen->height;
101- window = XCreateSimpleWindow(display, RootWindow(display, 0), screen_width / 2 - uxn_screen.width / 2, screen_height / 2 - uxn_screen.height / 2, uxn_screen.width, uxn_screen.height, 1, 0, 0);
102- display_hidecursor();
103- display_floating(display, window);
104- XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask | LeaveWindowMask);
105- XStoreName(display, window, "uxn11");
106- XSetClassHint(display, window, &class);
107- XMapWindow(display, window);
108- return 1;
109-}
110-
111-static unsigned int
112 emu_run(void)
113 {
114 int has_input, has_eof;
115 char expirations[8], coninp[CONINBUFSIZE];
116- struct pollfd fds[3];
117 static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
118+ struct pollfd fds[3];
119 /* timer */
120 fds[0].fd = XConnectionNumber(display);
121 fds[1].fd = timerfd_create(CLOCK_MONOTONIC, 0);
122@@ -1216,7 +1216,10 @@ emu_run(void)
123 console_input(0, CONSOLE_STD);
124 }
125 }
126- return 1;
127+ if(ximage)
128+ XDestroyImage(ximage);
129+ XDestroyWindow(display, window);
130+ XCloseDisplay(display);
131 }
132
133 int
134@@ -1224,7 +1227,7 @@ main(int argc, char **argv)
135 {
136 int i = 1;
137 if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
138- return !fprintf(stdout, "Uxn11 - Varvara Emulator, 30 Jun 2025.\n");
139+ return !fprintf(stdout, "Uxn11 - Varvara Emulator, 19 Jul 2025.\n");
140 else if(argc == 1)
141 return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
142 else if(!system_boot(argv[i++], argc > 2))
143@@ -1243,6 +1246,5 @@ main(int argc, char **argv)
144 return !fprintf(stdout, "Could not open display.\n");
145 emu_run();
146 console_close();
147- XDestroyImage(ximage), XDestroyWindow(display, window), XCloseDisplay(display);
148 return dev[0x0f] & 0x7f;
149 }