medvednikov

/

v4 Public
0 commits 0 issues 0 pull requests 0 contributors Discussions Projects CI

committed 56 years ago · View patch
3 files changed +56 -19
vlib/sokol/sapp/sapp_linux.c.v +14 -0

@@ -461,6 +461,17 @@ const map_private = 2

461461#include <X11/extensions/XInput2.h>

462462#include <X11/Xcursor/Xcursor.h>

463463

464+// X11 C typedefs are unsigned long based. Define them locally so V1 can

465+// type-check scalar operations while keeping the public aliases C-backed.

466+pub type C.XID = usize

467+pub type C.Atom = C.XID

468+pub type C.Window = C.XID

469+pub type C.Colormap = C.XID

470+pub type C.Cursor = C.XID

471+pub type C.KeySym = C.XID

472+pub type C.Time = C.XID

473+pub type C.VisualID = C.XID

474+

464475// X11 types

465476pub type XID = C.XID

466477pub type Atom = C.Atom

@@ -914,6 +925,9 @@ fn C.strncmp(s1 &char, s2 &char, n usize) int

914925const x_false = 0

915926const x_true = 1

916927const x_none = Atom(0)

928+const x_window_none = Window(0)

929+const x_colormap_none = Colormap(0)

930+const x_cursor_none = Cursor(0)

917931const xa_atom = Atom(4)

918932const xa_cardinal = Atom(6)

919933const alloc_none = 0

vlib/sokol/sapp/sapp_x11_linux.v +21 -19

@@ -967,22 +967,24 @@ fn x11_query_system_dpi() {

967967// === Keysym to unicode ===

968968

969969fn x11_keysym_to_unicode(keysym KeySym) i32 {

970+ keysym_value := u64(keysym)

970971 // Latin-1 characters (1:1 mapping)

971- if (keysym >= 0x0020 && keysym <= 0x007e) || (keysym >= 0x00a0 && keysym <= 0x00ff) {

972- return i32(keysym)

972+ if (keysym_value >= 0x0020 && keysym_value <= 0x007e)

973+ || (keysym_value >= 0x00a0 && keysym_value <= 0x00ff) {

974+ return i32(keysym_value)

973975 }

974976 // Directly encoded 24-bit UCS characters

975- if (keysym & 0xff000000) == 0x01000000 {

976- return i32(keysym & 0x00ffffff)

977+ if (keysym_value & 0xff000000) == 0x01000000 {

978+ return i32(keysym_value & 0x00ffffff)

977979 }

978980 // Binary search in table

979981 mut min := 0

980982 mut max := x11_keysymtab.len - 1

981983 for max >= min {

982984 mid := (min + max) / 2

983- if u64(x11_keysymtab[mid].keysym) < keysym {

985+ if u64(x11_keysymtab[mid].keysym) < keysym_value {

984986 min = mid + 1

985- } else if u64(x11_keysymtab[mid].keysym) > keysym {

987+ } else if u64(x11_keysymtab[mid].keysym) > keysym_value {

986988 max = mid - 1

987989 } else {

988990 return i32(x11_keysymtab[mid].ucs)

@@ -1090,7 +1092,7 @@ pub fn set_resizable(resizable bool) {

10901092}

10911093

10921094fn x11_set_resizable(resizable bool) {

1093- if g_sapp_state.x11.display == unsafe { nil } || g_sapp_state.x11.window == 0 {

1095+ if g_sapp_state.x11.display == unsafe { nil } || g_sapp_state.x11.window == x_window_none {

10941096 return

10951097 }

10961098 mut hints := C.XAllocSizeHints()

@@ -1144,7 +1146,7 @@ fn x11_create_window(visual_ &C.Visual, depth int) {

11441146 g_sapp_state.x11.window = C.XCreateWindow(g_sapp_state.x11.display, g_sapp_state.x11.root, 0,

11451147 0, u32(x11_window_width), u32(x11_window_height), 0, dep, input_output, vis, wamask, &wa)

11461148 x11_release_error_handler()

1147- if g_sapp_state.x11.window == 0 {

1149+ if g_sapp_state.x11.window == x_window_none {

11481150 eprintln('sokol_app: X11: failed to create window')

11491151 return

11501152 }

@@ -1168,14 +1170,14 @@ fn x11_create_window(visual_ &C.Visual, depth int) {

11681170}

11691171

11701172fn x11_destroy_window() {

1171- if g_sapp_state.x11.window != 0 {

1173+ if g_sapp_state.x11.window != x_window_none {

11721174 C.XUnmapWindow(g_sapp_state.x11.display, g_sapp_state.x11.window)

11731175 C.XDestroyWindow(g_sapp_state.x11.display, g_sapp_state.x11.window)

1174- g_sapp_state.x11.window = 0

1176+ g_sapp_state.x11.window = x_window_none

11751177 }

1176- if g_sapp_state.x11.colormap != 0 {

1178+ if g_sapp_state.x11.colormap != x_colormap_none {

11771179 C.XFreeColormap(g_sapp_state.x11.display, g_sapp_state.x11.colormap)

1178- g_sapp_state.x11.colormap = 0

1180+ g_sapp_state.x11.colormap = x_colormap_none

11791181 }

11801182 C.XFlush(g_sapp_state.x11.display)

11811183}

@@ -1233,7 +1235,7 @@ fn x11_create_standard_cursor(cursor MouseCursor, name &char, theme &char, size

12331235 C.XcursorImageDestroy(img)

12341236 }

12351237 }

1236- if g_sapp_state.x11.standard_cursors[idx] == 0 && fallback_native != 0 {

1238+ if g_sapp_state.x11.standard_cursors[idx] == x_cursor_none && fallback_native != 0 {

12371239 g_sapp_state.x11.standard_cursors[idx] = C.XCreateFontCursor(g_sapp_state.x11.display,

12381240 fallback_native)

12391241 }

@@ -1256,14 +1258,14 @@ fn x11_create_standard_cursors() {

12561258}

12571259

12581260fn x11_destroy_standard_cursors() {

1259- if g_sapp_state.x11.hidden_cursor != 0 {

1261+ if g_sapp_state.x11.hidden_cursor != x_cursor_none {

12601262 C.XFreeCursor(g_sapp_state.x11.display, g_sapp_state.x11.hidden_cursor)

1261- g_sapp_state.x11.hidden_cursor = 0

1263+ g_sapp_state.x11.hidden_cursor = x_cursor_none

12621264 }

12631265 for i in 0 .. mousecursor_num {

1264- if g_sapp_state.x11.standard_cursors[i] != 0 {

1266+ if g_sapp_state.x11.standard_cursors[i] != x_cursor_none {

12651267 C.XFreeCursor(g_sapp_state.x11.display, g_sapp_state.x11.standard_cursors[i])

1266- g_sapp_state.x11.standard_cursors[i] = 0

1268+ g_sapp_state.x11.standard_cursors[i] = x_cursor_none

12671269 }

12681270 }

12691271}

@@ -1279,10 +1281,10 @@ fn x11_update_cursor(cursor MouseCursor, shown bool) {

12791281 if shown {

12801282 if g_sapp_state.custom_cursor_bound[idx] {

12811283 xcursor := g_sapp_state.x11.custom_cursors[idx]

1282- if xcursor != 0 {

1284+ if xcursor != x_cursor_none {

12831285 C.XDefineCursor(g_sapp_state.x11.display, g_sapp_state.x11.window, xcursor)

12841286 }

1285- } else if g_sapp_state.x11.standard_cursors[idx] != 0 {

1287+ } else if g_sapp_state.x11.standard_cursors[idx] != x_cursor_none {

12861288 C.XDefineCursor(g_sapp_state.x11.display, g_sapp_state.x11.window,

12871289 g_sapp_state.x11.standard_cursors[idx])

12881290 } else {

vlib/v/tests/gg_import_check_test.v new file +21 -0

@@ -0,0 +1,21 @@

1+import os

2+

3+const issue_27584_vexe = os.quoted_path(@VEXE)

4+

5+fn test_importing_gg_checks_cleanly_on_linux() {

6+ $if !linux {

7+ return

8+ }

9+ source_path := os.join_path(os.vtmp_dir(), 'issue_27584_import_gg_${os.getpid()}.v')

10+ defer {

11+ os.rm(source_path) or {}

12+ }

13+ os.write_file(source_path, 'module main

14+

15+import gg as _

16+

17+fn main() {}

18+') or { panic(err) }

19+ res := os.execute('${issue_27584_vexe} -os linux -check ${os.quoted_path(source_path)}')

20+ assert res.exit_code == 0, res.output

21+}