diff options
| author | nasr <nsrddyn@gmail.com> | 2026-10-05 22:02:56 +0200 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-10-05 22:02:56 +0200 |
| commit | f6d3090f7fa76eb8e0dbe060b8490cb49c001c39 (patch) | |
| tree | 433c773997e51f22738acb8b04c4fd2fc6b1bdc9 /source/base/base_platform_linux_x11.cpp | |
init: base
Diffstat (limited to 'source/base/base_platform_linux_x11.cpp')
| -rw-r--r-- | source/base/base_platform_linux_x11.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source/base/base_platform_linux_x11.cpp b/source/base/base_platform_linux_x11.cpp new file mode 100644 index 0000000..62b5cbf --- /dev/null +++ b/source/base/base_platform_linux_x11.cpp | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | #ifdef X11 // @compile param | ||
| 2 | internal LinuxWindowHandle x11_create_window(MemArena *arena, u32 window_height, u32 window_width, | ||
| 3 | u32 display_x, u32 display_y) | ||
| 4 | { | ||
| 5 | |||
| 6 | Display *main_display = XOpenDisplay(0); | ||
| 7 | if (!main_display) { | ||
| 8 | Log("Error! Failed to open x11 display. Are you on X11?"); | ||
| 9 | } else { | ||
| 10 | Log("Successfully opened x11 display?\n"); | ||
| 11 | Log("Display: %p\n", main_display); | ||
| 12 | } | ||
| 13 | |||
| 14 | Window root = XDefaultRootWindow(main_display); | ||
| 15 | int screen = DefaultScreen(main_display); | ||
| 16 | |||
| 17 | Visual *v = DefaultVisual(main_display, screen); | ||
| 18 | |||
| 19 | XSetWindowAttributes wa = {.background_pixmap = None, | ||
| 20 | .background_pixel = | ||
| 21 | BlackPixel(main_display, DefaultScreen(main_display)), | ||
| 22 | .border_pixmap = CopyFromParent, | ||
| 23 | .border_pixel = 0, | ||
| 24 | .bit_gravity = ForgetGravity, | ||
| 25 | .win_gravity = NorthWestGravity, | ||
| 26 | .backing_store = NotUseful, | ||
| 27 | .backing_planes = 1, | ||
| 28 | .backing_pixel = 0, | ||
| 29 | .save_under = False, | ||
| 30 | .event_mask = 0, | ||
| 31 | .do_not_propagate_mask = 0, | ||
| 32 | .override_redirect = False, | ||
| 33 | .colormap = CopyFromParent, | ||
| 34 | .cursor = None}; | ||
| 35 | |||
| 36 | Window window = XCreateWindow(main_display, // display | ||
| 37 | root, // parent | ||
| 38 | display_x, // x | ||
| 39 | display_y, // y | ||
| 40 | window_width, // width | ||
| 41 | window_height, // height | ||
| 42 | 0, // border_width | ||
| 43 | CopyFromParent, // depth | ||
| 44 | CopyFromParent, // class | ||
| 45 | v, // depth | ||
| 46 | CWBackPixel, // visual | ||
| 47 | &wa); | ||
| 48 | |||
| 49 | XSetWindowBorder(main_display, window, 60); | ||
| 50 | XSelectInput(main_display, window, | ||
| 51 | ExposureMask | StructureNotifyMask | KeyReleaseMask | KeyPressMask); | ||
| 52 | XMapWindow(main_display, window); | ||
| 53 | |||
| 54 | LinuxWindowHandle out = {main_display, window}; | ||
| 55 | return out; | ||
| 56 | } | ||
| 57 | |||
| 58 | internal void x11_draw(LinuxWindowHandle *s, s32 start_x, s32 end_x, s32 start_y, s32 end_y) | ||
| 59 | { | ||
| 60 | |||
| 61 | u32 color = 0x55ffaaff; | ||
| 62 | GC gc = XCreateGC(s->display, s->window, 0, Nil); | ||
| 63 | XSetForeground(s->display, gc, color); | ||
| 64 | |||
| 65 | XFreeGC(s->display, gc); | ||
| 66 | } | ||
| 67 | |||
| 68 | internal s32 x11_cleanup(LinuxWindowHandle *s) | ||
| 69 | { | ||
| 70 | XCloseDisplay(s->display); | ||
| 71 | return 0; | ||
| 72 | } | ||
| 73 | |||
| 74 | internal s32 x11_read_input() { return 0; } | ||
| 75 | |||
| 76 | #endif // X11 \ No newline at end of file | ||
