summaryrefslogtreecommitdiff
path: root/reduced_system_layer.c
diff options
context:
space:
mode:
Diffstat (limited to 'reduced_system_layer.c')
-rwxr-xr-xreduced_system_layer.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/reduced_system_layer.c b/reduced_system_layer.c
index decd327..ffcec97 100755
--- a/reduced_system_layer.c
+++ b/reduced_system_layer.c
@@ -198,8 +198,6 @@ typedef struct {
};
} IP_Address;
-typedef i64 (*Thread_Proc)(void *user_data);
-
// UTF-8
i32 utf8_size(c32 c);
c32 utf8_read(i64 len, c8 *s);
@@ -626,6 +624,7 @@ i64 p_send(u16 slot, IP_Address address, i64 size, u8 *data, u16 *local_port) {
#include <X11/Xatom.h>
static i16 _key_table[512] = {0};
+static b8 _key_repeat[512] = {0};
static u32 _buffer[MAX_NUM_PIXELS] = {0};
static Input_Key _input[MAX_INPUT_SIZE] = {0};
static c8 _clipboard_buffer[MAX_CLIPBOARD_SIZE] = {0};
@@ -757,6 +756,11 @@ void p_init(void) {
i32 _display_width = DisplayWidth (_display, screen);
i32 _display_height = DisplayHeight(_display, screen);
+ if (platform.frame_width <= 0)
+ platform.frame_width = 400;
+ if (platform.frame_height <= 0)
+ platform.frame_height = 300;
+
i32 x = (_display_width - platform.frame_width) / 2;
i32 y = (_display_height - platform.frame_height) / 2;
@@ -804,6 +808,9 @@ void p_init(void) {
XStoreName(_display, _window, platform.title);
XMapWindow(_display, _window);
+
+ XPutImage(_display, _window, _gc, &_image, 0, 0, 0, 0, platform.frame_width, platform.frame_height);
+ XFlush(_display);
}
void p_cleanup(void) {
@@ -825,6 +832,7 @@ i32 p_handle_events(void) {
i32 num_events = 0;
memset(platform.key_pressed, 0, sizeof platform.key_pressed);
+ memset(_key_repeat, 0, sizeof _key_repeat);
platform.input_size = 0;
platform.cursor_dx = 0;
@@ -858,16 +866,16 @@ i32 p_handle_events(void) {
platform.cursor_y = ev.xbutton.y;
switch (ev.xbutton.button) {
case Button1:
- platform.key_down[BUTTON_LEFT] = 1;
- ++platform.key_pressed[BUTTON_LEFT];
+ platform.key_down[BUTTON_LEFT] = 1;
+ platform.key_pressed[BUTTON_LEFT] = 1;
break;
case Button2:
- platform.key_down[BUTTON_MIDDLE] = 1;
- ++platform.key_pressed[BUTTON_MIDDLE];
+ platform.key_down[BUTTON_MIDDLE] = 1;
+ platform.key_pressed[BUTTON_MIDDLE] = 1;
break;
case Button3:
- platform.key_down[BUTTON_RIGHT] = 1;
- ++platform.key_pressed[BUTTON_RIGHT];
+ platform.key_down[BUTTON_RIGHT] = 1;
+ platform.key_pressed[BUTTON_RIGHT] = 1;
break;
case Button4: ++platform.wheel_dy; break;
case Button5: --platform.wheel_dy; break;
@@ -894,14 +902,18 @@ i32 p_handle_events(void) {
i16 k = _key_table[ev.xkey.keycode];
platform.cursor_x = ev.xkey.x;
platform.cursor_y = ev.xkey.y;
- platform.key_down [k] = 1;
- platform.key_pressed[k]++;
+
+ platform.key_down[k] = 1;
+ if (!_key_repeat[k])
+ platform.key_pressed[k] = 1;
+
platform.key_down[MOD_CTRL] = !!(ev.xkey.state & ControlMask);
platform.key_down[MOD_SHIFT] = !!(ev.xkey.state & ShiftMask);
platform.key_down[MOD_ALT] = !!(ev.xkey.state & Mod1Mask);
platform.key_down[MOD_CAPS] = !!(ev.xkey.state & LockMask);
platform.key_down[MOD_NUM] = !!(ev.xkey.state & Mod2Mask);
platform.key_down[MOD_SCROLL] = !!(ev.xkey.state & Mod3Mask);
+
if (platform.input_size < MAX_INPUT_SIZE) {
if (k < 32 || k >= 128)
platform.input[platform.input_size++] = (Input_Key) {
@@ -930,6 +942,7 @@ i32 p_handle_events(void) {
};
}
}
+
if (!requested_clipboard) {
XConvertSelection(_display, _clipboard, _targets, _clipboard, _window, CurrentTime);
requested_clipboard = 1;
@@ -938,10 +951,13 @@ i32 p_handle_events(void) {
case KeyRelease: {
i16 k = _key_table[ev.xkey.keycode];
+
platform.cursor_x = ev.xkey.x;
platform.cursor_y = ev.xkey.y;
- platform.key_down [k] = 0;
- platform.key_pressed[k]--;
+
+ platform.key_down[k] = 0;
+ _key_repeat[k] = 1;
+
platform.key_down[MOD_CTRL] = !!(ev.xkey.state & ControlMask);
platform.key_down[MOD_SHIFT] = !!(ev.xkey.state & ShiftMask);
platform.key_down[MOD_ALT] = !!(ev.xkey.state & Mod1Mask);
@@ -995,15 +1011,15 @@ i32 p_handle_events(void) {
case SelectionNotify:
if (ev.xselection.property != None) {
- i64 len;
- u8 *data;
+ i64 len = 0;
+ u8 *data = NULL;
XGetWindowProperty(
_display,
_window,
_clipboard,
0,
- MAX_CLIPBOARD_SIZE,
+ MAX_CLIPBOARD_SIZE / 4,
False,
AnyPropertyType,
&(Atom) {0},
@@ -1017,7 +1033,7 @@ i32 p_handle_events(void) {
_target = None;
Atom *list = (Atom *) data;
- for (i64 i = 0; i < len; i++)
+ for (i64 i = 0; i < len / 4; i++)
if (list[i] == XA_STRING)
_target = XA_STRING;
else if (list[i] == _utf8_string) {
@@ -1065,9 +1081,6 @@ i32 p_handle_events(void) {
}
}
- for (i64 k = 0; k < (i64) (sizeof platform.key_pressed / sizeof *platform.key_pressed); ++k)
- platform.key_pressed[k] = platform.key_pressed[k] > 0 ? 1 : 0;
-
XWindowAttributes attrs;
XGetWindowAttributes(_display, _window, &attrs);