sgl
diff src/wsys_x11.c @ 7:edbfc96fe80d
glut wsys thingy and stuff...
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Sat, 14 May 2011 08:26:10 +0300 |
parents | 0cb438c86b98 |
children | 0b07dd867b2f |
line diff
1.1 --- a/src/wsys_x11.c Fri May 13 09:44:21 2011 +0300 1.2 +++ b/src/wsys_x11.c Sat May 14 08:26:10 2011 +0300 1.3 @@ -1,4 +1,12 @@ 1.4 +/* SimplyGL window system module for X11/GLX */ 1.5 +/* link-with: -lX11 */ 1.6 + 1.7 +#include "config.h" 1.8 + 1.9 +#ifdef USE_WSYS_MODULE_X11 1.10 + 1.11 #include <stdlib.h> 1.12 +#include <ctype.h> 1.13 #include <X11/Xlib.h> 1.14 #include <GL/glx.h> 1.15 #include "sgl.h" 1.16 @@ -37,12 +45,15 @@ 1.17 static void redisplay(void); 1.18 static void swap_buffers(void); 1.19 1.20 +static int get_modifiers(void); 1.21 + 1.22 /* event handling and friends */ 1.23 static void set_bits(long *mask, long bits); 1.24 static void clear_bits(long *mask, long bits); 1.25 static void set_event(int idx, int enable); 1.26 static int process_events(void); 1.27 static int handle_event(XEvent *xev); 1.28 +static void process_key(KeySym sym, int state); 1.29 static int translate_keysym(KeySym sym); 1.30 1.31 static struct wsys_module ws = { 1.32 @@ -57,6 +68,7 @@ 1.33 set_title, 1.34 redisplay, 1.35 swap_buffers, 1.36 + get_modifiers, 1.37 set_event, 1.38 process_events, 1.39 0 1.40 @@ -68,6 +80,7 @@ 1.41 static Atom xa_wm_prot, xa_wm_del_win; 1.42 static struct window *winlist; 1.43 static struct window *active_win, *prev_active; 1.44 +static int modkeys; 1.45 1.46 /* this is the only exported function, everything else should be static */ 1.47 void sgl_register_x11(void) 1.48 @@ -355,6 +368,11 @@ 1.49 glXSwapBuffers(dpy, active_win->win); 1.50 } 1.51 1.52 +static int get_modifiers(void) 1.53 +{ 1.54 + return modkeys; 1.55 +} 1.56 + 1.57 static void set_bits(long *mask, long bits) 1.58 { 1.59 *mask |= bits; 1.60 @@ -449,6 +467,7 @@ 1.61 int state; 1.62 struct window *win; 1.63 void (*func)(); 1.64 + KeySym sym; 1.65 1.66 if((win = find_window(xev->xany.window))) { 1.67 activate_window(win); 1.68 @@ -505,8 +524,10 @@ 1.69 case KeyRelease: 1.70 state = 0; 1.71 } 1.72 + sym = XLookupKeysym(&xev->xkey, 0); 1.73 + process_key(sym, state); 1.74 + 1.75 if((func = sgl_get_callback(SGL_KEYBOARD))) { 1.76 - KeySym sym = XLookupKeysym(&xev->xkey, 0); 1.77 func(translate_keysym(sym), state); 1.78 } 1.79 break; 1.80 @@ -540,9 +561,35 @@ 1.81 return 0; 1.82 } 1.83 1.84 +static void process_key(KeySym sym, int state) 1.85 +{ 1.86 + switch(sym) { 1.87 + case XK_Shift_L: 1.88 + case XK_Shift_R: 1.89 + modkeys = state ? (modkeys | SGL_MOD_SHIFT) : (modkeys & ~SGL_MOD_SHIFT); 1.90 + break; 1.91 + 1.92 + case XK_Control_L: 1.93 + case XK_Control_R: 1.94 + modkeys = state ? (modkeys | SGL_MOD_CONTROL) : (modkeys & ~SGL_MOD_CONTROL); 1.95 + break; 1.96 + 1.97 + case XK_Alt_L: 1.98 + case XK_Alt_R: 1.99 + modkeys = state ? (modkeys | SGL_MOD_ALT) : (modkeys & ~SGL_MOD_ALT); 1.100 + break; 1.101 + 1.102 + default: 1.103 + break; 1.104 + } 1.105 +} 1.106 + 1.107 static int translate_keysym(KeySym sym) 1.108 { 1.109 if(sym < 256) { 1.110 + if(isalpha(sym) && (modkeys & SGL_MOD_SHIFT)) { 1.111 + sym = toupper(sym); 1.112 + } 1.113 return sym; 1.114 } 1.115 1.116 @@ -562,3 +609,5 @@ 1.117 } 1.118 return (int)sym; 1.119 } 1.120 + 1.121 +#endif /* USE_WSYS_MODULE_X11 */