aboutsummaryrefslogtreecommitdiffstats
path: root/sway/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/container.c')
-rw-r--r--sway/container.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/sway/container.c b/sway/container.c
index 6c4206fb..f3e2b3ae 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -8,6 +8,7 @@
8#include "workspace.h" 8#include "workspace.h"
9#include "focus.h" 9#include "focus.h"
10#include "layout.h" 10#include "layout.h"
11#include "input_state.h"
11#include "log.h" 12#include "log.h"
12 13
13#define ASSERT_NONNULL(PTR) \ 14#define ASSERT_NONNULL(PTR) \
@@ -508,6 +509,70 @@ swayc_t *swayc_active_workspace_for(swayc_t *cont) {
508 } 509 }
509} 510}
510 511
512static bool pointer_test(swayc_t *view, void *_origin) {
513 const struct wlc_origin *origin = _origin;
514 // Determine the output that the view is under
515 swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT);
516 if (origin->x >= view->x && origin->y >= view->y
517 && origin->x < view->x + view->width && origin->y < view->y + view->height
518 && view->visible && parent == root_container.focused) {
519 return true;
520 }
521 return false;
522}
523
524swayc_t *container_under_pointer(void) {
525 // root.output->workspace
526 if (!root_container.focused || !root_container.focused->focused) {
527 return NULL;
528 }
529 swayc_t *lookup = root_container.focused->focused;
530 // Case of empty workspace
531 if (lookup->children == 0) {
532 return NULL;
533 }
534 struct wlc_origin origin;
535 wlc_pointer_get_origin(&origin);
536 while (lookup->type != C_VIEW) {
537 int i;
538 int len;
539 // if tabbed/stacked go directly to focused container, otherwise search
540 // children
541 if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) {
542 lookup = lookup->focused;
543 continue;
544 }
545 // if workspace, search floating
546 if (lookup->type == C_WORKSPACE) {
547 i = len = lookup->floating->length;
548 bool got_floating = false;
549 while (--i > -1) {
550 if (pointer_test(lookup->floating->items[i], &origin)) {
551 lookup = lookup->floating->items[i];
552 got_floating = true;
553 break;
554 }
555 }
556 if (got_floating) {
557 continue;
558 }
559 }
560 // search children
561 len = lookup->children->length;
562 for (i = 0; i < len; ++i) {
563 if (pointer_test(lookup->children->items[i], &origin)) {
564 lookup = lookup->children->items[i];
565 break;
566 }
567 }
568 // when border and titles are done, this could happen
569 if (i == len) {
570 break;
571 }
572 }
573 return lookup;
574}
575
511// Container information 576// Container information
512 577
513bool swayc_is_fullscreen(swayc_t *view) { 578bool swayc_is_fullscreen(swayc_t *view) {