floating: nested functions make the callbacks a lot more easier & beautiful
This commit is contained in:
parent
89c0caaec4
commit
bcd479ca92
|
@ -29,7 +29,7 @@
|
|||
/* On which border was the dragging initiated? */
|
||||
typedef enum { BORDER_LEFT, BORDER_RIGHT, BORDER_TOP, BORDER_BOTTOM} border_t;
|
||||
/* Callback for dragging */
|
||||
typedef void(*callback_t)(xcb_connection_t*, Client*, border_t, Rect*, xcb_button_press_event_t*, uint32_t, uint32_t);
|
||||
typedef void(*callback_t)(Rect*, uint32_t, uint32_t);
|
||||
|
||||
/* Forward definitions */
|
||||
static void drag_pointer(xcb_connection_t *conn, Client *client, xcb_button_press_event_t *event,
|
||||
|
@ -138,12 +138,20 @@ void toggle_floating_mode(xcb_connection_t *conn, Client *client, bool automatic
|
|||
xcb_flush(conn);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Callback for resizing windows
|
||||
* Called whenever the user clicks on a border (not the titlebar!) of a floating window.
|
||||
* Determines on which border the user clicked and launches the drag_pointer function
|
||||
* with the resize_callback.
|
||||
*
|
||||
*/
|
||||
static void resize_callback(xcb_connection_t *conn, Client *client, border_t border, Rect *old_rect,
|
||||
xcb_button_press_event_t *event, uint32_t new_x, uint32_t new_y) {
|
||||
int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_press_event_t *event) {
|
||||
|
||||
LOG("floating border click\n");
|
||||
|
||||
border_t border;
|
||||
|
||||
void resize_callback(Rect *old_rect, uint32_t new_x, uint32_t new_y) {
|
||||
switch (border) {
|
||||
case BORDER_RIGHT:
|
||||
client->rect.width = old_rect->width + (new_x - event->root_x);
|
||||
|
@ -170,17 +178,6 @@ static void resize_callback(xcb_connection_t *conn, Client *client, border_t bor
|
|||
xcb_flush(conn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called whenever the user clicks on a border (not the titlebar!) of a floating window.
|
||||
* Determines on which border the user clicked and launches the drag_pointer function
|
||||
* with the resize_callback.
|
||||
*
|
||||
*/
|
||||
int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_press_event_t *event) {
|
||||
|
||||
LOG("floating border click\n");
|
||||
|
||||
border_t border;
|
||||
if (event->event_y < 2)
|
||||
border = BORDER_TOP;
|
||||
else if (event->event_y >= (client->rect.height - 2))
|
||||
|
@ -201,8 +198,16 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void drag_window_callback(xcb_connection_t *conn, Client *client, border_t border, Rect *old_rect,
|
||||
xcb_button_press_event_t *event, uint32_t new_x, uint32_t new_y) {
|
||||
|
||||
/*
|
||||
* Called when the user clicked on the titlebar of a floating window.
|
||||
* Calls the drag_pointer function with the drag_window callback
|
||||
*
|
||||
*/
|
||||
void floating_drag_window(xcb_connection_t *conn, Client *client, xcb_button_press_event_t *event) {
|
||||
LOG("floating_drag_window\n");
|
||||
|
||||
void drag_window_callback(Rect *old_rect, uint32_t new_x, uint32_t new_y) {
|
||||
/* Reposition the client correctly while moving */
|
||||
client->rect.x = old_rect->x + (new_x - event->root_x);
|
||||
client->rect.y = old_rect->y + (new_y - event->root_y);
|
||||
|
@ -213,13 +218,6 @@ static void drag_window_callback(xcb_connection_t *conn, Client *client, border_
|
|||
/* fake_absolute_configure_notify flushes */
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when the user clicked on the titlebar of a floating window.
|
||||
* Calls the drag_pointer function with the drag_window callback
|
||||
*
|
||||
*/
|
||||
void floating_drag_window(xcb_connection_t *conn, Client *client, xcb_button_press_event_t *event) {
|
||||
LOG("floating_drag_window\n");
|
||||
|
||||
drag_pointer(conn, client, event, BORDER_TOP /* irrelevant */, drag_window_callback);
|
||||
}
|
||||
|
@ -278,7 +276,7 @@ static void drag_pointer(xcb_connection_t *conn, Client *client, xcb_button_pres
|
|||
new_x = ((xcb_motion_notify_event_t*)inside_event)->root_x;
|
||||
new_y = ((xcb_motion_notify_event_t*)inside_event)->root_y;
|
||||
|
||||
callback(conn, client, border, &old_rect, event, new_x, new_y);
|
||||
callback(&old_rect, new_x, new_y);
|
||||
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue