swk

static widget kit
git clone git://git.suckless.org/swk
Log | Files | Refs | README | LICENSE

commit ee131f1a38870739d153d5e97cdd4b2209a37cba
parent 4eb513ebff25ba37f57510f06bce12d93619311f
Author: pancake <pancake@nopcode.org>
Date:   Fri,  2 Jul 2010 01:40:54 +0200

fix x11 keyboard input (backspace, return)
fix vertical align text in buttons in x11
clean warnings and remove deprecated code
Diffstat:
config.def.h | 4+++-
gi_sdl.c | 2+-
gi_x11.c | 39+++++++++++++++++++++------------------
swk.c | 10+---------
t/test.c | 2+-
5 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -22,10 +22,12 @@ static SwkKeyBind keys[] = { { Ctrl, 'j', swk_focus_next }, { Ctrl, 'k', swk_focus_prev }, + { Ctrl, 'h' , swk_column_move_left }, + { Ctrl, 'l', swk_column_move_right }, //{ Ctrl, 8 , swk_focus_first }, //{ Ctrl, 9 , swk_focus_prev }, { Ctrl, 8 , swk_column_move_left }, - { Ctrl, 12 , swk_column_move_right }, + { Ctrl, 12 , swk_column_move_right }, { 0 , 9 , swk_focus_next }, { Ctrl, 10 , swk_focus_next }, { Ctrl, 11 , swk_focus_prev }, diff --git a/gi_sdl.c b/gi_sdl.c @@ -190,8 +190,8 @@ swk_gi_event(SwkWindow *w, int dowait) { mousedowny = TOUCHSCREEN?-1:event.button.y; break; case SDL_KEYDOWN: - ret->data.key.modmask = 0; ret->type = EKey; + ret->data.key.modmask = 0; if(event.key.keysym.mod & KMOD_CTRL) ret->data.key.modmask |= Ctrl; if(event.key.keysym.mod & KMOD_SHIFT) diff --git a/gi_x11.c b/gi_x11.c @@ -1,6 +1,7 @@ /* See LICENSE file for copyright and license details. */ #define _BSD_SOURCE // strdup #include <stdio.h> +#include <string.h> #include <stdlib.h> #include <ctype.h> #include <locale.h> @@ -12,13 +13,10 @@ #include "config.h" #define FONTNAME "-*-*-medium-*-*-*-14-*-*-*-*-*-*-*" -#define FONTFACTOR 2 /* XXX */ static Drawable drawable; -static GC gc; static int fs = FONTSIZE; // TODO: we need fsW and fsH static Window window; -static XFontSet set; static int screen; static Display *display = NULL; static int has_event = 0; @@ -38,7 +36,7 @@ swk_gi_init(SwkWindow *w) { if(first) { first = 0; display = XOpenDisplay(NULL); - if (display == NULL) { + if(display == NULL) { fprintf(stderr, "Cannot open display\n"); return 0; } @@ -48,7 +46,6 @@ swk_gi_init(SwkWindow *w) { 10, 10, w->r.w, w->r.h, 1, BlackPixel(display, screen), WhitePixel(display, screen)); - gc = XCreateGC(display, window, 0, NULL); drawable = XCreatePixmap(display, window, w->r.w, w->r.h, DefaultDepth(display, screen)); XSelectInput(display, window, EVENTMASK); XMapWindow(display, window); @@ -90,15 +87,11 @@ swk_gi_event(SwkWindow *w, int dowait) { if(has_event); switch(event.type) { - default: ret = NULL; break; case Expose: ret->type = EExpose; ret->data.expose.x = ret->data.expose.y = \ ret->data.expose.w = ret->data.expose.h = 0; break; - case VisibilityNotify: - printf("visi\n"); - break; case MotionNotify: // TODO: move this stuff into swk.c.. shoudlnt be backend dependent // fprintf(stderr, "event: motion (%d,%d)\n", event.motion.x,event.motion.y); @@ -150,25 +143,35 @@ swk_gi_event(SwkWindow *w, int dowait) { mousedowny = event.xbutton.y; break; case KeyPress: - printf ("KEY PRESSED\n"); - ret->data.key.modmask = 0; ret->type = EKey; - //num = XLookupString(&event, buf, sizeof buf, &ksym, NULL); - XLookupString(&event, NULL, 0, &ksym, NULL); -printf("ksym=%d\n", ksym); - ret->data.key.keycode = ksym; + XLookupString(&event.xkey, NULL, 0, &ksym, NULL); + printf("ksym=%d\n", (int)ksym); + switch(ksym) { + case XK_BackSpace: + ret->data.key.keycode = 8; + break; + case XK_Return: + ret->data.key.keycode = '\n'; + break; + default: + ret->data.key.keycode = ksym; + } + ret->data.key.modmask = 0; if(event.xkey.state&ShiftMask) ret->data.key.modmask |= Shift; if(event.xkey.state&Mod1Mask) ret->data.key.modmask |= Alt; if(event.xkey.state&ControlMask) ret->data.key.modmask |= Ctrl; - fprintf(stderr, "event: key %d %d\n", - ret->data.key.modmask, ret->data.key.keycode); + fprintf(stderr, "event: key %d %d (%c)\n", + ret->data.key.modmask, ret->data.key.keycode, ret->data.key.keycode); break; case 0://SDL_QUIT: ret->type = EQuit; break; + default: + ret = NULL; + break; } has_event = 0; return ret; @@ -225,7 +228,7 @@ void swk_gi_text(Rect r, const char *text) { if(!text||!*text) return; - XDrawString(display, window, DefaultGC(display, screen), r.x*fs, (1+r.y)*fs, text, strlen (text)); + XDrawString(display, window, DefaultGC(display, screen), r.x*fs, ((1+r.y)*fs)-3, text, strlen (text)); } void diff --git a/swk.c b/swk.c @@ -235,14 +235,6 @@ swk_handle_event(SwkEvent *e) { break; } } - /* XXX: this must be implemented in app? .. sure */ - if(e->data.key.keycode==27) { - e->box = e->win->box; - e->type = EQuit; - swk_exit(e->win); - break; - } - // send key to focused box e->box = e->win->box; if(e->win->box) e->win->box->cb(e); @@ -260,7 +252,7 @@ swk_handle_event(SwkEvent *e) { } break; case EClick: - // TODO: do this needs to be in config.h? + // TODO: move click events in config.h switch(e->data.click.button) { case 4: swk_scroll_up(e->win); diff --git a/t/test.c b/t/test.c @@ -78,7 +78,7 @@ static void mybutton_about(SwkEvent *e) { } swk_button(e); } -//--------- + static SwkBox scrollwin[] = { SWK_BOX_NEWLINE(0), { .cb=swk_label, .text="Scroll to change value", },