made better, reduced code duplication

master
taiyu 9 years ago
parent 8752a166ed
commit 3a21ba020f

@ -28,15 +28,19 @@ static bool pointer_test(swayc_t *view, void *_origin) {
return false;
}
void focus_pointer(void) {
swayc_t *focused = find_container(&root_container, pointer_test, &mouse_origin);
if (focused) {
sway_log(L_DEBUG, "Switching focus to %p", focused);
unfocus_all(&root_container);
focus_view(focused);
} else {
focus_view(active_workspace);
swayc_t *focus_pointer(void) {
swayc_t *focused = get_focused_container(&root_container);
if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) {
swayc_t *pointer = find_container(&root_container, pointer_test, &mouse_origin);
if (pointer && focused != pointer) {
unfocus_all(&root_container);
focus_view(pointer);
} else if (!focused){
focus_view(active_workspace);
}
focused = pointer;
}
return focused;
}
static bool handle_output_created(wlc_handle output) {
@ -194,31 +198,16 @@ static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct w
if (!config->focus_follows_mouse) {
return true;
}
swayc_t *focused = get_focused_container(&root_container);
if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) {
swayc_t *c = find_container(&root_container, pointer_test, (void *)origin);
if (c && c != focused) {
sway_log(L_DEBUG, "Switching focus to %p", c);
unfocus_all(&root_container);
focus_view(c);
}
}
focus_pointer();
return true;
}
static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers,
uint32_t button, enum wlc_button_state state) {
swayc_t *focused = get_focused_container(&root_container);
if (state == WLC_BUTTON_STATE_PRESSED
&& !(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) {
swayc_t *c = find_container(&root_container, pointer_test, &mouse_origin);
if (c && c != focused) {
sway_log(L_DEBUG, "Switching focus to %p", c);
unfocus_all(&root_container);
focus_view(c);
return false;
}
return true;
if (state == WLC_BUTTON_STATE_PRESSED) {
swayc_t *pointer = focus_pointer();
return !(pointer && pointer != focused);
}
return true;
}

@ -6,7 +6,7 @@
extern struct wlc_interface interface;
//set focus to current pointer location
void focus_pointer(void);
//set focus to current pointer location and return focused container
swayc_t *focus_pointer(void);
#endif

Loading…
Cancel
Save