]> git.sur5r.net Git - i3/i3/blobdiff - src/randr.c
Merge pull request #3327 from orestisf1993/rename-mouse-bug
[i3/i3] / src / randr.c
index efdd0352fe5386c6365ecd29d24c1b95bbb99109..d4d7402a704ccc1dec3f7efb4e56b86d1c6f8aa9 100644 (file)
@@ -114,6 +114,20 @@ Output *get_output_containing(unsigned int x, unsigned int y) {
     return NULL;
 }
 
+/*
+ * Returns the active output which contains the midpoint of the given rect. If
+ * such an output doesn't exist, returns the output which contains most of the
+ * rectangle or NULL if there is no output which intersects with it.
+ *
+ */
+Output *get_output_from_rect(Rect rect) {
+    unsigned int mid_x = rect.x + rect.width / 2;
+    unsigned int mid_y = rect.y + rect.height / 2;
+    Output *output = get_output_containing(mid_x, mid_y);
+
+    return output ? output : output_containing_rect(rect);
+}
+
 /*
  * Returns the active output which spans exactly the area specified by
  * rect or NULL if there is no output like this.
@@ -413,11 +427,7 @@ void init_ws_for_output(Output *output, Con *content) {
         if (strcmp(assignment->output, output_primary_name(output)) != 0)
             continue;
 
-        /* check if this workspace actually exists */
-        Con *workspace = NULL, *out;
-        TAILQ_FOREACH(out, &(croot->nodes_head), nodes)
-        GREP_FIRST(workspace, output_get_content(out),
-                   !strcasecmp(child->name, assignment->name));
+        Con *workspace = get_existing_workspace_by_name(assignment->name);
         if (workspace == NULL)
             continue;
 
@@ -846,8 +856,9 @@ void randr_query_outputs(void) {
     /* If there's no randr output, enable the output covering the root window. */
     if (any_randr_output_active()) {
         DLOG("Active RandR output found. Disabling root output.\n");
-        if (root_output->active)
+        if (root_output && root_output->active) {
             root_output->to_be_disabled = true;
+        }
     } else {
         DLOG("No active RandR output found. Enabling root output.\n");
         root_output->active = true;