Skip to content

Commit

Permalink
buttons: Fix background functions for non-default layouts
Browse files Browse the repository at this point in the history
While the configured layout is taken into account for positioning
the buttons, the mapping from button function states to button
position states just assumed the default button layout in LTR
locales.
Do a proper mapping depending on the actual layout instead.

Based on metacity commit: 6a52883c2b670ad645257373515d1e704408b93d
From: Florian Müllner <[email protected]>
Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=638700
  • Loading branch information
infirit committed Nov 12, 2014
1 parent a65e3c4 commit 7116f6e
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 16 deletions.
14 changes: 0 additions & 14 deletions src/ui/frames.c
Original file line number Diff line number Diff line change
Expand Up @@ -2677,20 +2677,6 @@ meta_frames_paint_to_drawable (MetaFrames *frames,
break;
}

/* Map button function states to button position states */
button_states[META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND] =
button_states[META_BUTTON_TYPE_MENU];
button_states[META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND] =
META_BUTTON_STATE_NORMAL;
button_states[META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND] =
META_BUTTON_STATE_NORMAL;
button_states[META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND] =
button_states[META_BUTTON_TYPE_MINIMIZE];
button_states[META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND] =
button_states[META_BUTTON_TYPE_MAXIMIZE];
button_states[META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND] =
button_states[META_BUTTON_TYPE_CLOSE];

meta_core_get (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), frame->xwindow,
META_CORE_GET_FRAME_FLAGS, &flags,
META_CORE_GET_FRAME_TYPE, &type,
Expand Down
105 changes: 103 additions & 2 deletions src/ui/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,38 @@ meta_frame_layout_get_borders (const MetaFrameLayout *layout,
}
}

static MetaButtonType
map_button_function_to_type (MetaButtonFunction function)
{
switch (function)
{
case META_BUTTON_FUNCTION_SHADE:
return META_BUTTON_TYPE_SHADE;
case META_BUTTON_FUNCTION_ABOVE:
return META_BUTTON_TYPE_ABOVE;
case META_BUTTON_FUNCTION_STICK:
return META_BUTTON_TYPE_STICK;
case META_BUTTON_FUNCTION_UNSHADE:
return META_BUTTON_TYPE_UNSHADE;
case META_BUTTON_FUNCTION_UNABOVE:
return META_BUTTON_TYPE_UNABOVE;
case META_BUTTON_FUNCTION_UNSTICK:
return META_BUTTON_TYPE_UNSTICK;
case META_BUTTON_FUNCTION_MENU:
return META_BUTTON_TYPE_MENU;
case META_BUTTON_FUNCTION_MINIMIZE:
return META_BUTTON_TYPE_MINIMIZE;
case META_BUTTON_FUNCTION_MAXIMIZE:
return META_BUTTON_TYPE_MAXIMIZE;
case META_BUTTON_FUNCTION_CLOSE:
return META_BUTTON_TYPE_CLOSE;
case META_BUTTON_FUNCTION_LAST:
return META_BUTTON_TYPE_LAST;
}

return META_BUTTON_TYPE_LAST;
}

static MetaButtonSpace*
rect_for_function (MetaFrameGeometry *fgeom,
MetaFrameFlags flags,
Expand Down Expand Up @@ -827,6 +859,11 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
}
}

/* Save the button layout */
fgeom->button_layout = *button_layout;
fgeom->n_left_buttons = n_left;
fgeom->n_right_buttons = n_right;

/* center buttons vertically */
button_y = (fgeom->top_height -
(button_height + layout->button_border.top + layout->button_border.bottom)) / 2 + layout->button_border.top;
Expand Down Expand Up @@ -4392,6 +4429,64 @@ meta_frame_style_unref (MetaFrameStyle *style)
}
}

static MetaButtonState
map_button_state (MetaButtonType button_type,
const MetaFrameGeometry *fgeom,
int middle_bg_offset,
MetaButtonState button_states[META_BUTTON_TYPE_LAST])
{
MetaButtonFunction function = META_BUTTON_FUNCTION_LAST;

switch (button_type)
{
/* First hande functions, which map directly */
case META_BUTTON_TYPE_SHADE:
case META_BUTTON_TYPE_ABOVE:
case META_BUTTON_TYPE_STICK:
case META_BUTTON_TYPE_UNSHADE:
case META_BUTTON_TYPE_UNABOVE:
case META_BUTTON_TYPE_UNSTICK:
case META_BUTTON_TYPE_MENU:
case META_BUTTON_TYPE_MINIMIZE:
case META_BUTTON_TYPE_MAXIMIZE:
case META_BUTTON_TYPE_CLOSE:
return button_states[button_type];

/* Map position buttons to the corresponding function */
case META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND:
if (fgeom->n_right_buttons > 0)
function = fgeom->button_layout.right_buttons[0];
break;
case META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND:
if (fgeom->n_right_buttons > 0)
function = fgeom->button_layout.right_buttons[fgeom->n_right_buttons - 1];
break;
case META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND:
if (middle_bg_offset + 1 < fgeom->n_right_buttons)
function = fgeom->button_layout.right_buttons[middle_bg_offset + 1];
break;
case META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND:
if (fgeom->n_left_buttons > 0)
function = fgeom->button_layout.left_buttons[0];
break;
case META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND:
if (fgeom->n_left_buttons > 0)
function = fgeom->button_layout.left_buttons[fgeom->n_left_buttons - 1];
break;
case META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND:
if (middle_bg_offset + 1 < fgeom->n_left_buttons)
function = fgeom->button_layout.left_buttons[middle_bg_offset + 1];
break;
case META_BUTTON_TYPE_LAST:
break;
}

if (function != META_BUTTON_FUNCTION_LAST)
return button_states[map_button_function_to_type (function)];

return META_BUTTON_STATE_LAST;
}

static MetaDrawOpList*
get_button (MetaFrameStyle *style,
MetaButtonType type,
Expand Down Expand Up @@ -4799,10 +4894,12 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style,
j = 0;
while (j < META_BUTTON_TYPE_LAST)
{
MetaButtonState button_state;

button_rect (j, fgeom, middle_bg_offset, &rect);

op_list = get_button (style, j, button_states[j]);
button_state = map_button_state (j, fgeom, middle_bg_offset, button_states)
op_list = get_button (style, j, button_state);

if (op_list)
{
Expand Down Expand Up @@ -4853,6 +4950,8 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style,
j = 0;
while (j < META_BUTTON_TYPE_LAST)
{
MetaButtonState button_state;

button_rect (j, fgeom, middle_bg_offset, &rect);

rect.x += x_offset;
Expand All @@ -4869,7 +4968,9 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style,
{
MetaDrawOpList *op_list;

op_list = get_button (style, j, button_states[j]);
button_state = map_button_state (j, fgeom, middle_bg_offset, button_states);

op_list = get_button (style, j, button_state);

if (op_list)
{
Expand Down
5 changes: 5 additions & 0 deletions src/ui/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ struct _MetaFrameGeometry
GdkRectangle right_right_background;
/* End of button rects (if changed adjust memset hack) */

/* Saved button layout */
MetaButtonLayout button_layout;
int n_left_buttons;
int n_right_buttons;

/* Round corners */
guint top_left_corner_rounded_radius;
guint top_right_corner_rounded_radius;
Expand Down

0 comments on commit 7116f6e

Please sign in to comment.