Merge pull request #933 from alkino/click_title_bar

add click on title_bar to focus a container
This commit is contained in:
Drew DeVault 2016-10-06 14:53:26 -04:00 committed by GitHub
commit 6fb7d0e30c
3 changed files with 38 additions and 0 deletions

View File

@ -243,6 +243,10 @@ swayc_t *swayc_active_workspace_for(swayc_t *view);
* Finds the container currently underneath the pointer. * Finds the container currently underneath the pointer.
*/ */
swayc_t *container_under_pointer(void); swayc_t *container_under_pointer(void);
/**
* Finds the first container following a callback.
*/
swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *), const void *data);
/** /**
* Returns true if a container is fullscreen. * Returns true if a container is fullscreen.

View File

@ -722,6 +722,25 @@ swayc_t *container_under_pointer(void) {
return lookup; return lookup;
} }
swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *), const void *data) {
if (container->children == NULL || container->children->length == 0) {
return NULL;
}
for (int i = 0; i < container->children->length; ++i) {
if (f(container->children->items[i], data)) {
return container->children->items[i];
}
swayc_t *find = container_find(container->children->items[i], f, data);
if (find != NULL) {
return find;
}
}
return NULL;
}
// Container information // Container information
bool swayc_is_fullscreen(swayc_t *view) { bool swayc_is_fullscreen(swayc_t *view) {

View File

@ -776,6 +776,14 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
return EVENT_PASSTHROUGH; return EVENT_PASSTHROUGH;
} }
bool swayc_border_check(swayc_t *c, const void *_origin) {
const struct wlc_point *origin = _origin;
if (origin->x >= c->title_bar_geometry.origin.x && origin->y >= c->title_bar_geometry.origin.y
&& origin->x < (c->title_bar_geometry.origin.x + (int)c->title_bar_geometry.size.w) && origin->y < (c->title_bar_geometry.origin.y + (int)c->title_bar_geometry.size.h)) {
return true;
}
return false;
}
static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers,
uint32_t button, enum wlc_button_state state, const struct wlc_point *origin) { uint32_t button, enum wlc_button_state state, const struct wlc_point *origin) {
@ -840,6 +848,13 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
// Check whether to change focus // Check whether to change focus
swayc_t *pointer = pointer_state.view; swayc_t *pointer = pointer_state.view;
if (pointer) { if (pointer) {
swayc_t *ws = swayc_parent_by_type(focused, C_WORKSPACE);
swayc_t *find = container_find(ws, &swayc_border_check, origin);
if (find != NULL) {
set_focused_container(find);
return EVENT_HANDLED;
}
if (focused != pointer) { if (focused != pointer) {
set_focused_container(pointer_state.view); set_focused_container(pointer_state.view);
} }