diff options
author | Jonas Ådahl <jadahl@gmail.com> | 2018-10-24 14:24:22 +0200 |
---|---|---|
committer | Jonas Ådahl <jadahl@gmail.com> | 2018-11-08 13:21:21 +0100 |
commit | 640a04d0e4bd8c15a74b23fd449c9c4b2f572e70 (patch) | |
tree | b80bd5c79ab068ec52ce8e2d932c05f74ff6048a /src/x11/window-x11.c | |
parent | 5fc07fcc23030fb81c567ae22ee118faab4afa4c (diff) | |
download | mutter-640a04d0e4bd8c15a74b23fd449c9c4b2f572e70.tar.gz |
window: Make edge constraint code more readable
It relied on indices in arrays determining tile direction and
non-obvious bitmask logic to translate to _GTK_EDGE_CONSTRAINTS. Change
this to explicitly named edge constraints, and clear translation methods
that converts between mutters and GTK+s edge constraint formats.
Diffstat (limited to 'src/x11/window-x11.c')
-rw-r--r-- | src/x11/window-x11.c | 81 |
1 files changed, 71 insertions, 10 deletions
diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index e67cf2a5c..ac304e3fa 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -50,6 +50,18 @@ #include "x11/window-props.h" #include "x11/xprops.h" +enum _MetaGtkEdgeConstraints +{ + META_GTK_EDGE_CONSTRAINT_TOP_TILED = 1 << 0, + META_GTK_EDGE_CONSTRAINT_TOP_RESIZABLE = 1 << 1, + META_GTK_EDGE_CONSTRAINT_RIGHT_TILED = 1 << 2, + META_GTK_EDGE_CONSTRAINT_RIGHT_RESIZABLE = 1 << 3, + META_GTK_EDGE_CONSTRAINT_BOTTOM_TILED = 1 << 4, + META_GTK_EDGE_CONSTRAINT_BOTTOM_RESIZABLE = 1 << 5, + META_GTK_EDGE_CONSTRAINT_LEFT_TILED = 1 << 6, + META_GTK_EDGE_CONSTRAINT_LEFT_RESIZABLE = 1 << 7 +} MetaGtkEdgeConstraints; + G_DEFINE_TYPE_WITH_PRIVATE (MetaWindowX11, meta_window_x11, META_TYPE_WINDOW) static void @@ -906,22 +918,71 @@ update_net_frame_extents (MetaWindow *window) meta_x11_error_trap_pop (x11_display); } +static gboolean +is_edge_constraint_resizable (MetaEdgeConstraint constraint) +{ + switch (constraint) + { + case META_EDGE_CONSTRAINT_NONE: + case META_EDGE_CONSTRAINT_WINDOW: + return TRUE; + case META_EDGE_CONSTRAINT_MONITOR: + return FALSE; + } + + g_assert_not_reached (); +} + +static gboolean +is_edge_constraint_tiled (MetaEdgeConstraint constraint) +{ + switch (constraint) + { + case META_EDGE_CONSTRAINT_NONE: + return FALSE; + case META_EDGE_CONSTRAINT_WINDOW: + case META_EDGE_CONSTRAINT_MONITOR: + return TRUE; + } + + g_assert_not_reached (); +} + +static unsigned long +edge_constraints_to_gtk_edge_constraints (MetaWindow *window) +{ + unsigned long gtk_edge_constraints = 0; + + if (is_edge_constraint_tiled (window->edge_constraints.top)) + gtk_edge_constraints |= META_GTK_EDGE_CONSTRAINT_TOP_TILED; + if (is_edge_constraint_resizable (window->edge_constraints.top)) + gtk_edge_constraints |= META_GTK_EDGE_CONSTRAINT_TOP_RESIZABLE; + + if (is_edge_constraint_tiled (window->edge_constraints.right)) + gtk_edge_constraints |= META_GTK_EDGE_CONSTRAINT_RIGHT_TILED; + if (is_edge_constraint_resizable (window->edge_constraints.right)) + gtk_edge_constraints |= META_GTK_EDGE_CONSTRAINT_RIGHT_RESIZABLE; + + if (is_edge_constraint_tiled (window->edge_constraints.bottom)) + gtk_edge_constraints |= META_GTK_EDGE_CONSTRAINT_BOTTOM_TILED; + if (is_edge_constraint_resizable (window->edge_constraints.bottom)) + gtk_edge_constraints |= META_GTK_EDGE_CONSTRAINT_BOTTOM_RESIZABLE; + + if (is_edge_constraint_tiled (window->edge_constraints.left)) + gtk_edge_constraints |= META_GTK_EDGE_CONSTRAINT_LEFT_TILED; + if (is_edge_constraint_resizable (window->edge_constraints.left)) + gtk_edge_constraints |= META_GTK_EDGE_CONSTRAINT_LEFT_RESIZABLE; + + return gtk_edge_constraints; +} + static void update_gtk_edge_constraints (MetaWindow *window) { MetaX11Display *x11_display = window->display->x11_display; - MetaEdgeConstraint *constraints = window->edge_constraints; unsigned long data[1]; - /* Edge constraints */ - data[0] = (constraints[0] != META_EDGE_CONSTRAINT_NONE ? 1 : 0) << 0 | - (constraints[0] != META_EDGE_CONSTRAINT_MONITOR ? 1 : 0) << 1 | - (constraints[1] != META_EDGE_CONSTRAINT_NONE ? 1 : 0) << 2 | - (constraints[1] != META_EDGE_CONSTRAINT_MONITOR ? 1 : 0) << 3 | - (constraints[2] != META_EDGE_CONSTRAINT_NONE ? 1 : 0) << 4 | - (constraints[2] != META_EDGE_CONSTRAINT_MONITOR ? 1 : 0) << 5 | - (constraints[3] != META_EDGE_CONSTRAINT_NONE ? 1 : 0) << 6 | - (constraints[3] != META_EDGE_CONSTRAINT_MONITOR ? 1 : 0) << 7; + data[0] = edge_constraints_to_gtk_edge_constraints (window); meta_verbose ("Setting _GTK_EDGE_CONSTRAINTS to %lu\n", data[0]); |