Commit 4511fe77 authored by Cedric Roux's avatar Cedric Roux

add key modifiers to button event

parent 262ab709
......@@ -227,7 +227,7 @@ static void horizontal_hints(gui *_gui, widget *_w, int *width, int *height)
}
static void horizontal_button(gui *_g, widget *_this, int x, int y,
int button, int up)
int key_modifiers, int button, int up)
{
LOGD("BUTTON container horizontal %p xy %d %d button %d up %d\n", _this, x, y, button, up);
struct gui *g = _g;
......@@ -237,7 +237,7 @@ static void horizontal_button(gui *_g, widget *_this, int x, int y,
l = this->common.children;
while (l) {
if (l->item->x <= x && x < l->item->x + l->item->width) {
l->item->button(g, l->item, x, y, button, up);
l->item->button(g, l->item, x, y, key_modifiers, button, up);
break;
}
l = l->next;
......@@ -245,7 +245,7 @@ static void horizontal_button(gui *_g, widget *_this, int x, int y,
}
static void vertical_button(gui *_g, widget *_this, int x, int y,
int button, int up)
int key_modifiers, int button, int up)
{
LOGD("BUTTON container vertical %p xy %d %d button %d up %d\n", _this, x, y, button, up);
struct gui *g = _g;
......@@ -255,7 +255,7 @@ static void vertical_button(gui *_g, widget *_this, int x, int y,
l = this->common.children;
while (l) {
if (l->item->y <= y && y < l->item->y + l->item->height) {
l->item->button(g, l->item, x, y, button, up);
l->item->button(g, l->item, x, y, key_modifiers, button, up);
break;
}
l = l->next;
......
......@@ -12,6 +12,11 @@ typedef void widget;
#define BACKGROUND_COLOR 0
#define FOREGROUND_COLOR 1
/* key modifiers */
#define KEY_SHIFT (1<<0)
#define KEY_CONTROL (1<<1)
#define KEY_ALT (1<<2)
gui *gui_init(void);
/* position = -1 to put at the end */
......
......@@ -53,7 +53,8 @@ struct widget {
void (*paint)(gui *g, widget *this);
void (*clear)(gui *g, widget *this);
/* user input */
void (*button)(gui *g, widget *this, int x, int y, int button, int up);
void (*button)(gui *g, widget *this, int x, int y, int key_modifiers,
int button, int up);
};
struct widget_list {
......
......@@ -45,7 +45,8 @@ widget *new_label(gui *_gui, const char *label)
return w;
}
static void button(gui *gui, widget *_this, int x, int y, int button, int up)
static void button(gui *gui, widget *_this, int x, int y,
int key_modifiers, int button, int up)
{
LOGD("BUTTON label %p xy %d %d button %d up %d\n", _this, x, y, button, up);
......@@ -55,7 +56,8 @@ static void button(gui *gui, widget *_this, int x, int y, int button, int up)
}
/* we could use default_button, but it's in widget.c, so, well... */
static void no_button(gui *gui, widget *_this, int x,int y,int button,int up)
static void no_button(gui *gui, widget *_this, int x, int y,
int key_modifiers, int button, int up)
{
/* do nothing */
}
......
......@@ -50,14 +50,15 @@ static void hints(gui *_gui, widget *_w, int *width, int *height)
else { *width = *height = 1; }
}
static void button(gui *_g, widget *_this, int x, int y, int button, int up)
static void button(gui *_g, widget *_this, int x, int y,
int key_modifiers, int button, int up)
{
LOGD("BUTTON positioner %p xy %d %d button %d up %d\n", _this, x, y, button, up);
struct gui *g = _g;
struct positioner_widget *this = _this;
struct widget_list *l = this->common.children;
if (l != NULL)
l->item->button(g, l->item, x, y, button, up);
l->item->button(g, l->item, x, y, key_modifiers, button, up);
}
static void paint(gui *_gui, widget *_this)
......
......@@ -44,7 +44,8 @@ static void allocate(
LOGD("ALLOCATE textlist %p xywh %d %d %d %d nlines %d\n", this, x, y, width, height, this->allocated_nlines);
}
static void button(gui *_g, widget *_this, int x, int y, int button, int up)
static void button(gui *_g, widget *_this, int x, int y,
int key_modifiers, int button, int up)
{
struct gui *g = _g;
struct textlist_widget *this = _this;
......
......@@ -54,7 +54,8 @@ static void allocate(gui *_gui, widget *_this,
gui_notify(_gui, "resize", _this, &width);
}
static void button(gui *_g, widget *_this, int x, int y, int button, int up)
static void button(gui *_g, widget *_this, int x, int y,
int key_modifiers, int button, int up)
{
struct gui *g = _g;
struct timeline_widget *this = _this;
......
......@@ -55,13 +55,14 @@ static void paint(gui *_gui, widget *_this)
g->xwin = NULL; /* TODO: remove? it's just in case */
}
static void button(gui *_g, widget *_this, int x, int y, int button, int up)
static void button(gui *_g, widget *_this, int x, int y,
int key_modifiers, int button, int up)
{
struct gui *g = _g;
struct toplevel_window_widget *this = _this;
g->xwin = this->x;
this->common.children->item->button(_g, this->common.children->item,
x, y, button, up);
x, y, key_modifiers, button, up);
g->xwin = NULL; /* TODO: remove? it's just in case */
}
......
......@@ -14,8 +14,8 @@ static void default_add_child(
gui *_gui, widget *_this, widget *child, int position);
static void default_del_child(gui *_gui, widget *_this, widget *child);
static void default_hints(gui *g, widget *this, int *width, int *height);
static void default_button(gui *gui, widget *_this, int x, int y, int button,
int up);
static void default_button(gui *gui, widget *_this, int x, int y,
int key_modifiers, int button, int up);
static void toplevel_list_append(struct gui *g, struct widget *e)
{
......@@ -228,8 +228,8 @@ static void default_hints(gui *g, widget *this, int *width, int *height)
*height = 1;
}
static void default_button(gui *gui, widget *_this, int x, int y, int button,
int up)
static void default_button(gui *gui, widget *_this, int x, int y,
int key_modifiers, int button, int up)
{
/* nothing */
}
......
......@@ -171,13 +171,21 @@ void x_events(gui *_gui)
break;
case ButtonPress:
if ((w = find_x_window(g, ev.xbutton.window)) != NULL) {
w->common.button(g, w, ev.xbutton.x, ev.xbutton.y,
int key_modifiers = 0;
if (ev.xbutton.state & ShiftMask) key_modifiers |= KEY_SHIFT;
if (ev.xbutton.state & Mod1Mask) key_modifiers |= KEY_ALT;
if (ev.xbutton.state & ControlMask) key_modifiers |= KEY_CONTROL;
w->common.button(g, w, ev.xbutton.x, ev.xbutton.y, key_modifiers,
ev.xbutton.button, 0);
}
break;
case ButtonRelease:
if ((w = find_x_window(g, ev.xbutton.window)) != NULL) {
w->common.button(g, w, ev.xbutton.x, ev.xbutton.y,
int key_modifiers = 0;
if (ev.xbutton.state & ShiftMask) key_modifiers |= KEY_SHIFT;
if (ev.xbutton.state & Mod1Mask) key_modifiers |= KEY_ALT;
if (ev.xbutton.state & ControlMask) key_modifiers |= KEY_CONTROL;
w->common.button(g, w, ev.xbutton.x, ev.xbutton.y, key_modifiers,
ev.xbutton.button, 1);
}
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment