summaryrefslogtreecommitdiffstats
path: root/sway/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/container.c')
-rw-r--r--sway/container.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/sway/container.c b/sway/container.c
index 6c4206fb..4f9e2b5e 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,68 @@ 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 mouse_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 while (lookup->type != C_VIEW) {
535 int i;
536 int len;
537 // if tabbed/stacked go directly to focused container, otherwise search
538 // children
539 if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) {
540 lookup = lookup->focused;
541 continue;
542 }
543 // if workspace, search floating
544 if (lookup->type == C_WORKSPACE) {
545 i = len = lookup->floating->length;
546 bool got_floating = false;
547 while (--i > -1) {
548 if (pointer_test(lookup->floating->items[i], &pointer_state.origin)) {
549 lookup = lookup->floating->items[i];
550 got_floating = true;
551 break;
552 }
553 }
554 if (got_floating) {
555 continue;
556 }
557 }
558 // search children
559 len = lookup->children->length;
560 for (i = 0; i < len; ++i) {
561 if (pointer_test(lookup->children->items[i], &pointer_state.origin)) {
562 lookup = lookup->children->items[i];
563 break;
564 }
565 }
566 // when border and titles are done, this could happen
567 if (i == len) {
568 break;
569 }
570 }
571 return lookup;
572}
573
511// Container information 574// Container information
512 575
513bool swayc_is_fullscreen(swayc_t *view) { 576bool swayc_is_fullscreen(swayc_t *view) {