mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 00:11:28 +00:00
container: Move container_under_pointer here from handlers.
This commit is contained in:
parent
ad1cd0a3bd
commit
865b30f138
|
@ -5,6 +5,8 @@ typedef struct sway_container swayc_t;
|
||||||
|
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
|
||||||
|
extern struct wlc_origin mouse_origin;
|
||||||
|
|
||||||
enum swayc_types{
|
enum swayc_types{
|
||||||
C_ROOT,
|
C_ROOT,
|
||||||
C_OUTPUT,
|
C_OUTPUT,
|
||||||
|
@ -98,6 +100,8 @@ swayc_t *swayc_by_name(const char *name);
|
||||||
swayc_t *swayc_active_output(void);
|
swayc_t *swayc_active_output(void);
|
||||||
swayc_t *swayc_active_workspace(void);
|
swayc_t *swayc_active_workspace(void);
|
||||||
swayc_t *swayc_active_workspace_for(swayc_t *view);
|
swayc_t *swayc_active_workspace_for(swayc_t *view);
|
||||||
|
// set focus to current pointer location and return focused container
|
||||||
|
swayc_t *container_under_pointer(void);
|
||||||
|
|
||||||
// Container information
|
// Container information
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,6 @@
|
||||||
#include <wlc/wlc.h>
|
#include <wlc/wlc.h>
|
||||||
|
|
||||||
extern struct wlc_interface interface;
|
extern struct wlc_interface interface;
|
||||||
extern struct wlc_origin mouse_origin;
|
|
||||||
extern uint32_t keys_pressed[32];
|
extern uint32_t keys_pressed[32];
|
||||||
|
|
||||||
// set focus to current pointer location and return focused container
|
|
||||||
swayc_t *container_under_pointer(void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "workspace.h"
|
#include "workspace.h"
|
||||||
#include "focus.h"
|
#include "focus.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
#include "input_state.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#define ASSERT_NONNULL(PTR) \
|
#define ASSERT_NONNULL(PTR) \
|
||||||
|
@ -508,6 +509,68 @@ swayc_t *swayc_active_workspace_for(swayc_t *cont) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool pointer_test(swayc_t *view, void *_origin) {
|
||||||
|
const struct mouse_origin *origin = _origin;
|
||||||
|
// Determine the output that the view is under
|
||||||
|
swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT);
|
||||||
|
if (origin->x >= view->x && origin->y >= view->y
|
||||||
|
&& origin->x < view->x + view->width && origin->y < view->y + view->height
|
||||||
|
&& view->visible && parent == root_container.focused) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
swayc_t *container_under_pointer(void) {
|
||||||
|
// root.output->workspace
|
||||||
|
if (!root_container.focused || !root_container.focused->focused) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
swayc_t *lookup = root_container.focused->focused;
|
||||||
|
// Case of empty workspace
|
||||||
|
if (lookup->children == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
while (lookup->type != C_VIEW) {
|
||||||
|
int i;
|
||||||
|
int len;
|
||||||
|
// if tabbed/stacked go directly to focused container, otherwise search
|
||||||
|
// children
|
||||||
|
if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) {
|
||||||
|
lookup = lookup->focused;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// if workspace, search floating
|
||||||
|
if (lookup->type == C_WORKSPACE) {
|
||||||
|
i = len = lookup->floating->length;
|
||||||
|
bool got_floating = false;
|
||||||
|
while (--i > -1) {
|
||||||
|
if (pointer_test(lookup->floating->items[i], &pointer_state.origin)) {
|
||||||
|
lookup = lookup->floating->items[i];
|
||||||
|
got_floating = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (got_floating) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// search children
|
||||||
|
len = lookup->children->length;
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
if (pointer_test(lookup->children->items[i], &pointer_state.origin)) {
|
||||||
|
lookup = lookup->children->items[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// when border and titles are done, this could happen
|
||||||
|
if (i == len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lookup;
|
||||||
|
}
|
||||||
|
|
||||||
// Container information
|
// Container information
|
||||||
|
|
||||||
bool swayc_is_fullscreen(swayc_t *view) {
|
bool swayc_is_fullscreen(swayc_t *view) {
|
||||||
|
|
|
@ -24,68 +24,6 @@
|
||||||
// Event handled by sway and should not be sent to client
|
// Event handled by sway and should not be sent to client
|
||||||
#define EVENT_HANDLED true
|
#define EVENT_HANDLED true
|
||||||
|
|
||||||
static bool pointer_test(swayc_t *view, void *_origin) {
|
|
||||||
const struct mouse_origin *origin = _origin;
|
|
||||||
// Determine the output that the view is under
|
|
||||||
swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT);
|
|
||||||
if (origin->x >= view->x && origin->y >= view->y
|
|
||||||
&& origin->x < view->x + view->width && origin->y < view->y + view->height
|
|
||||||
&& view->visible && parent == root_container.focused) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
swayc_t *container_under_pointer(void) {
|
|
||||||
// root.output->workspace
|
|
||||||
if (!root_container.focused || !root_container.focused->focused) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
swayc_t *lookup = root_container.focused->focused;
|
|
||||||
// Case of empty workspace
|
|
||||||
if (lookup->children == 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
while (lookup->type != C_VIEW) {
|
|
||||||
int i;
|
|
||||||
int len;
|
|
||||||
// if tabbed/stacked go directly to focused container, otherwise search
|
|
||||||
// children
|
|
||||||
if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) {
|
|
||||||
lookup = lookup->focused;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// if workspace, search floating
|
|
||||||
if (lookup->type == C_WORKSPACE) {
|
|
||||||
i = len = lookup->floating->length;
|
|
||||||
bool got_floating = false;
|
|
||||||
while (--i > -1) {
|
|
||||||
if (pointer_test(lookup->floating->items[i], &pointer_state.origin)) {
|
|
||||||
lookup = lookup->floating->items[i];
|
|
||||||
got_floating = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (got_floating) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// search children
|
|
||||||
len = lookup->children->length;
|
|
||||||
for (i = 0; i < len; ++i) {
|
|
||||||
if (pointer_test(lookup->children->items[i], &pointer_state.origin)) {
|
|
||||||
lookup = lookup->children->items[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// when border and titles are done, this could happen
|
|
||||||
if (i == len) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lookup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Handles */
|
/* Handles */
|
||||||
|
|
||||||
static bool handle_output_created(wlc_handle output) {
|
static bool handle_output_created(wlc_handle output) {
|
||||||
|
|
Loading…
Reference in a new issue