Basic mouse events to windows
This commit is contained in:
parent
e39c08965e
commit
f4c6ef10ad
@ -127,6 +127,8 @@ static void device_to_window(yutani_server_window_t * window, int32_t x, int32_t
|
||||
*out_x = x - window->x;
|
||||
*out_y = y - window->y;
|
||||
|
||||
if (!window->rotation) return;
|
||||
|
||||
double t_x = *out_x - (window->width / 2);
|
||||
double t_y = *out_y - (window->height / 2);
|
||||
|
||||
@ -771,8 +773,17 @@ static void handle_mouse_event(yutani_globals_t * yg, struct yutani_msg_mouse_ev
|
||||
}
|
||||
}
|
||||
} else if ((me->event.buttons & YUTANI_MOUSE_BUTTON_LEFT) && (!yg->kbd_state.k_alt)) {
|
||||
yg->mouse_state = YUTANI_MOUSE_STATE_DRAGGING;
|
||||
set_focused_at(yg, yg->mouse_x / MOUSE_SCALE, yg->mouse_y / MOUSE_SCALE);
|
||||
yg->mouse_window = get_focused(yg);
|
||||
yg->mouse_moved = 0;
|
||||
yg->mouse_drag_button = YUTANI_MOUSE_BUTTON_LEFT;
|
||||
device_to_window(yg->mouse_window, yg->mouse_x / MOUSE_SCALE, yg->mouse_y / MOUSE_SCALE, &yg->mouse_click_x, &yg->mouse_click_y);
|
||||
yutani_msg_t * response = yutani_msg_build_window_mouse_event(yg->mouse_window->wid, yg->mouse_click_x, yg->mouse_click_y, -1, -1, me->event.buttons, YUTANI_MOUSE_EVENT_DOWN);
|
||||
pex_send(yg->server, yg->mouse_window->owner, response->size, (char *)response);
|
||||
free(response);
|
||||
} else {
|
||||
/* XXX Arbitrary mouse movement, not dragging */
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -792,9 +803,31 @@ static void handle_mouse_event(yutani_globals_t * yg, struct yutani_msg_mouse_ev
|
||||
case YUTANI_MOUSE_STATE_DRAGGING:
|
||||
{
|
||||
if (!(me->event.buttons & yg->mouse_drag_button)) {
|
||||
|
||||
/* Mouse released */
|
||||
yg->mouse_state = YUTANI_MOUSE_STATE_NORMAL;
|
||||
int32_t old_x = yg->mouse_click_x;
|
||||
int32_t old_y = yg->mouse_click_y;
|
||||
device_to_window(yg->mouse_window, yg->mouse_x / MOUSE_SCALE, yg->mouse_y / MOUSE_SCALE, &yg->mouse_click_x, &yg->mouse_click_y);
|
||||
if (!yg->mouse_moved) {
|
||||
yutani_msg_t * response = yutani_msg_build_window_mouse_event(yg->mouse_window->wid, yg->mouse_click_x, yg->mouse_click_y, -1, -1, me->event.buttons, YUTANI_MOUSE_EVENT_CLICK);
|
||||
pex_send(yg->server, yg->mouse_window->owner, response->size, (char *)response);
|
||||
free(response);
|
||||
} else {
|
||||
yutani_msg_t * response = yutani_msg_build_window_mouse_event(yg->mouse_window->wid, yg->mouse_click_x, yg->mouse_click_y, old_x, old_y, me->event.buttons, YUTANI_MOUSE_EVENT_RAISE);
|
||||
pex_send(yg->server, yg->mouse_window->owner, response->size, (char *)response);
|
||||
free(response);
|
||||
}
|
||||
} else {
|
||||
|
||||
yg->mouse_state = YUTANI_MOUSE_STATE_DRAGGING;
|
||||
yg->mouse_moved = 1;
|
||||
int32_t old_x = yg->mouse_click_x;
|
||||
int32_t old_y = yg->mouse_click_y;
|
||||
device_to_window(yg->mouse_window, yg->mouse_x / MOUSE_SCALE, yg->mouse_y / MOUSE_SCALE, &yg->mouse_click_x, &yg->mouse_click_y);
|
||||
if (old_x != yg->mouse_click_x || old_y != yg->mouse_click_y) {
|
||||
yutani_msg_t * response = yutani_msg_build_window_mouse_event(yg->mouse_window->wid, yg->mouse_click_x, yg->mouse_click_y, old_x, old_y, me->event.buttons, YUTANI_MOUSE_EVENT_DRAG);
|
||||
pex_send(yg->server, yg->mouse_window->owner, response->size, (char *)response);
|
||||
free(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -87,6 +87,9 @@ typedef struct {
|
||||
int mouse_drag_button;
|
||||
int mouse_moved;
|
||||
|
||||
int32_t mouse_click_x;
|
||||
int32_t mouse_click_y;
|
||||
|
||||
key_event_state_t kbd_state;
|
||||
|
||||
} yutani_globals_t;
|
||||
|
@ -215,6 +215,27 @@ yutani_msg_t * yutani_msg_build_window_focus_change(yutani_wid_t wid, int focuse
|
||||
return msg;
|
||||
}
|
||||
|
||||
yutani_msg_t * yutani_msg_build_window_mouse_event(yutani_wid_t wid, int32_t new_x, int32_t new_y, int32_t old_x, int32_t old_y, uint8_t buttons, uint8_t command) {
|
||||
size_t s = sizeof(struct yutani_message) + sizeof(struct yutani_msg_window_mouse_event);
|
||||
yutani_msg_t * msg = malloc(s);
|
||||
|
||||
msg->magic = YUTANI_MSG__MAGIC;
|
||||
msg->type = YUTANI_MSG_WINDOW_MOUSE_EVENT;
|
||||
msg->size = s;
|
||||
|
||||
struct yutani_msg_window_mouse_event * mw = (void *)msg->data;
|
||||
|
||||
mw->wid = wid;
|
||||
mw->new_x = new_x;
|
||||
mw->new_y = new_y;
|
||||
mw->old_x = old_x;
|
||||
mw->old_y = old_y;
|
||||
mw->buttons = buttons;
|
||||
mw->command = command;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
int yutani_msg_send(yutani_t * y, yutani_msg_t * msg) {
|
||||
return pex_reply(y->sock, msg->size, (char *)msg);
|
||||
}
|
||||
|
@ -79,6 +79,16 @@ struct yutani_msg_window_focus_change {
|
||||
int focused;
|
||||
};
|
||||
|
||||
struct yutani_msg_window_mouse_event {
|
||||
yutani_wid_t wid;
|
||||
int32_t new_x;
|
||||
int32_t new_y;
|
||||
int32_t old_x;
|
||||
int32_t old_y;
|
||||
uint8_t buttons;
|
||||
uint8_t command;
|
||||
};
|
||||
|
||||
struct yutani_msg_mouse_event {
|
||||
yutani_wid_t wid;
|
||||
mouse_device_packet_t event;
|
||||
@ -111,6 +121,7 @@ typedef struct yutani_window {
|
||||
#define YUTANI_MSG_WINDOW_HIDE 0x00000009
|
||||
#define YUTANI_MSG_WINDOW_STACK 0x0000000A
|
||||
#define YUTANI_MSG_WINDOW_FOCUS_CHANGE 0x0000000B
|
||||
#define YUTANI_MSG_WINDOW_MOUSE_EVENT 0x0000000C
|
||||
#define YUTANI_MSG_GOODBYE 0x000000F0
|
||||
|
||||
/* Server responses */
|
||||
@ -130,6 +141,11 @@ typedef struct yutani_window {
|
||||
#define YUTANI_MOUSE_STATE_DRAGGING 2
|
||||
#define YUTANI_MOUSE_STATE_RESIZING 3
|
||||
|
||||
#define YUTANI_MOUSE_EVENT_CLICK 0
|
||||
#define YUTANI_MOUSE_EVENT_DRAG 1
|
||||
#define YUTANI_MOUSE_EVENT_RAISE 2
|
||||
#define YUTANI_MOUSE_EVENT_DOWN 3
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
@ -150,6 +166,7 @@ yutani_msg_t * yutani_msg_build_mouse_event(yutani_wid_t wid, mouse_device_packe
|
||||
yutani_msg_t * yutani_msg_build_window_close(yutani_wid_t wid);
|
||||
yutani_msg_t * yutani_msg_build_window_stack(yutani_wid_t wid, int z);
|
||||
yutani_msg_t * yutani_msg_build_window_focus_change(yutani_wid_t wid, int focused);
|
||||
yutani_msg_t * yutani_msg_build_window_mouse_event(yutani_wid_t wid, int32_t new_x, int32_t new_y, int32_t old_x, int32_t old_y, uint8_t buttons, uint8_t command);
|
||||
|
||||
int yutani_msg_send(yutani_t * y, yutani_msg_t * msg);
|
||||
yutani_t * yutani_context_create(FILE * socket);
|
||||
|
Loading…
Reference in New Issue
Block a user