window_x11.odin 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // WIP! Does not function yet.
  2. #+build linux
  3. #+private file
  4. package karl2d
  5. @(private="package")
  6. WINDOW_INTERFACE_X11 :: Window_Interface {
  7. state_size = x11_state_size,
  8. init = x11_init,
  9. shutdown = x11_shutdown,
  10. window_handle = x11_window_handle,
  11. process_events = x11_process_events,
  12. get_events = x11_get_events,
  13. get_width = x11_get_width,
  14. get_height = x11_get_height,
  15. clear_events = x11_clear_events,
  16. set_position = x11_set_position,
  17. set_size = x11_set_size,
  18. get_window_scale = x11_get_window_scale,
  19. set_flags = x11_set_flags,
  20. is_gamepad_active = x11_is_gamepad_active,
  21. get_gamepad_axis = x11_get_gamepad_axis,
  22. set_gamepad_vibration = x11_set_gamepad_vibration,
  23. set_internal_state = x11_set_internal_state,
  24. }
  25. import X "vendor:x11/xlib"
  26. import "base:runtime"
  27. import "core:log"
  28. import "core:fmt"
  29. _ :: log
  30. _ :: fmt
  31. x11_state_size :: proc() -> int {
  32. return size_of(X11_State)
  33. }
  34. x11_init :: proc(
  35. window_state: rawptr,
  36. window_width: int,
  37. window_height: int,
  38. window_title: string,
  39. flags: Window_Flags,
  40. allocator: runtime.Allocator,
  41. ) {
  42. s = (^X11_State)(window_state)
  43. s.allocator = allocator
  44. s.flags = flags
  45. s.width = window_width
  46. s.height = window_height
  47. display := X.OpenDisplay(nil)
  48. window := X.CreateSimpleWindow(
  49. display,
  50. X.DefaultRootWindow(display),
  51. 0, 0,
  52. u32(window_width), u32(window_height),
  53. 0,
  54. 0x00000000,
  55. 0x00000000,
  56. )
  57. X.StoreName(display, window, frame_cstring(window_title))
  58. X.SelectInput(display, window, {.KeyPress, .KeyRelease})
  59. X.MapWindow(display, window)
  60. }
  61. x11_shutdown :: proc() {
  62. }
  63. x11_window_handle :: proc() -> Window_Handle {
  64. return {}
  65. }
  66. x11_process_events :: proc() {
  67. }
  68. x11_get_events :: proc() -> []Window_Event {
  69. return s.events[:]
  70. }
  71. x11_get_width :: proc() -> int {
  72. return s.width
  73. }
  74. x11_get_height :: proc() -> int {
  75. return s.height
  76. }
  77. x11_clear_events :: proc() {
  78. runtime.clear(&s.events)
  79. }
  80. x11_set_position :: proc(x: int, y: int) {
  81. }
  82. x11_set_size :: proc(w, h: int) {
  83. }
  84. x11_get_window_scale :: proc() -> f32 {
  85. return 1
  86. }
  87. x11_set_flags :: proc(flags: Window_Flags) {
  88. s.flags = flags
  89. }
  90. x11_is_gamepad_active :: proc(gamepad: int) -> bool {
  91. if gamepad < 0 || gamepad >= MAX_GAMEPADS {
  92. return false
  93. }
  94. return false
  95. }
  96. x11_get_gamepad_axis :: proc(gamepad: int, axis: Gamepad_Axis) -> f32 {
  97. if gamepad < 0 || gamepad >= MAX_GAMEPADS {
  98. return 0
  99. }
  100. return 0
  101. }
  102. x11_set_gamepad_vibration :: proc(gamepad: int, left: f32, right: f32) {
  103. if gamepad < 0 || gamepad >= MAX_GAMEPADS {
  104. return
  105. }
  106. }
  107. x11_set_internal_state :: proc(state: rawptr) {
  108. assert(state != nil)
  109. s = (^X11_State)(state)
  110. }
  111. X11_State :: struct {
  112. allocator: runtime.Allocator,
  113. width: int,
  114. height: int,
  115. events: [dynamic]Window_Event,
  116. flags: Window_Flags,
  117. }
  118. s: ^X11_State