Commit 9e001cec authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

libmetacity: add meta_theme_set_button_layout

parent a5b82c84
......@@ -35,6 +35,8 @@ struct _MetaTheme
MetaThemeType type;
MetaThemeImpl *impl;
MetaButtonLayout button_layout;
gboolean composited;
PangoFontDescription *titlebar_font;
......@@ -359,6 +361,7 @@ static void
meta_theme_constructed (GObject *object)
{
MetaTheme *theme;
const gchar *button_layout;
G_OBJECT_CLASS (meta_theme_parent_class)->constructed (object);
......@@ -372,6 +375,9 @@ meta_theme_constructed (GObject *object)
g_assert_not_reached ();
meta_theme_impl_set_composited (theme->impl, theme->composited);
button_layout = "appmenu:minimize,maximize,close";
meta_theme_set_button_layout (theme, button_layout, FALSE);
}
static void
......@@ -547,6 +553,14 @@ meta_theme_invalidate (MetaTheme *theme)
g_hash_table_remove_all (theme->title_heights);
}
void
meta_theme_set_button_layout (MetaTheme *theme,
const gchar *button_layout,
gboolean invert)
{
theme->button_layout = meta_button_layout_new (button_layout, invert);
}
void
meta_theme_set_composited (MetaTheme *theme,
gboolean composited)
......@@ -602,14 +616,13 @@ meta_theme_get_frame_borders (MetaTheme *theme,
}
void
meta_theme_calc_geometry (MetaTheme *theme,
const gchar *variant,
MetaFrameType type,
MetaFrameFlags flags,
gint client_width,
gint client_height,
const MetaButtonLayout *button_layout,
MetaFrameGeometry *fgeom)
meta_theme_calc_geometry (MetaTheme *theme,
const gchar *variant,
MetaFrameType type,
MetaFrameFlags flags,
gint client_width,
gint client_height,
MetaFrameGeometry *fgeom)
{
MetaFrameStyle *style;
MetaThemeImplClass *impl_class;
......@@ -630,7 +643,7 @@ meta_theme_calc_geometry (MetaTheme *theme,
impl_class->calc_geometry (theme->impl, style->layout, style_info,
title_height, flags, client_width, client_height,
button_layout, type, fgeom);
&theme->button_layout, type, fgeom);
}
void
......@@ -642,7 +655,6 @@ meta_theme_draw_frame (MetaTheme *theme,
gint client_width,
gint client_height,
const gchar *title,
const MetaButtonLayout *button_layout,
MetaButtonState button_states[META_BUTTON_TYPE_LAST],
GdkPixbuf *mini_icon,
GdkPixbuf *icon)
......@@ -669,7 +681,7 @@ meta_theme_draw_frame (MetaTheme *theme,
impl_class->calc_geometry (theme->impl, style->layout, style_info,
title_height, flags, client_width, client_height,
button_layout, type, &fgeom);
&theme->button_layout, type, &fgeom);
impl_class->draw_frame (theme->impl, style, style_info, cr, &fgeom,
title_layout, flags, button_states, mini_icon, icon);
......
......@@ -154,6 +154,10 @@ gboolean meta_theme_load (MetaTheme *theme,
void meta_theme_invalidate (MetaTheme *theme);
void meta_theme_set_button_layout (MetaTheme *theme,
const gchar *button_layout,
gboolean invert);
void meta_theme_set_composited (MetaTheme *theme,
gboolean composited);
......@@ -172,7 +176,6 @@ void meta_theme_calc_geometry (MetaTheme *theme,
MetaFrameFlags flags,
gint client_width,
gint client_height,
const MetaButtonLayout *button_layout,
MetaFrameGeometry *fgeom);
void meta_theme_draw_frame (MetaTheme *theme,
......@@ -183,7 +186,6 @@ void meta_theme_draw_frame (MetaTheme *theme,
gint client_width,
gint client_height,
const gchar *title,
const MetaButtonLayout *button_layout,
MetaButtonState button_states[META_BUTTON_TYPE_LAST],
GdkPixbuf *mini_icon,
GdkPixbuf *icon);
......
......@@ -552,6 +552,10 @@ prefs_changed_callback (MetaPreference pref,
{
switch (pref)
{
case META_PREF_BUTTON_LAYOUT:
meta_ui_update_button_layout ();
break;
case META_PREF_THEME_NAME:
case META_PREF_THEME_TYPE:
case META_PREF_COMPOSITING_MANAGER:
......@@ -579,7 +583,6 @@ prefs_changed_callback (MetaPreference pref,
case META_PREF_NUM_WORKSPACES:
case META_PREF_KEYBINDINGS:
case META_PREF_DISABLE_WORKAROUNDS:
case META_PREF_BUTTON_LAYOUT:
case META_PREF_WORKSPACE_NAMES:
case META_PREF_VISUAL_BELL:
case META_PREF_AUDIBLE_BELL:
......
......@@ -94,7 +94,7 @@ static gboolean force_fullscreen = TRUE;
static gboolean alt_tab_thumbnails = FALSE;
static GDesktopVisualBellType visual_bell_type = G_DESKTOP_VISUAL_BELL_FULLSCREEN_FLASH;
static MetaButtonLayout button_layout;
static gchar *button_layout;
static MetaPlacementMode placement_mode = META_PLACEMENT_MODE_SMART;
......@@ -1199,43 +1199,16 @@ mouse_button_mods_handler (GVariant *value,
return TRUE;
}
static gboolean
button_layout_equal (const MetaButtonLayout *a,
const MetaButtonLayout *b)
{
int i;
i = 0;
while (i < META_BUTTON_FUNCTION_LAST)
{
if (a->left_buttons[i] != b->left_buttons[i])
return FALSE;
if (a->right_buttons[i] != b->right_buttons[i])
return FALSE;
if (a->left_buttons_has_spacer[i] != b->left_buttons_has_spacer[i])
return FALSE;
if (a->right_buttons_has_spacer[i] != b->right_buttons_has_spacer[i])
return FALSE;
i++;
}
return TRUE;
}
static void
update_button_layout (const gchar *string_value)
{
gboolean invert;
MetaButtonLayout new_layout;
if (g_strcmp0 (button_layout, string_value) == 0)
return;
invert = meta_ui_get_direction() == META_UI_DIRECTION_RTL;
new_layout = meta_button_layout_new (string_value, invert);
g_free (button_layout);
button_layout = g_strdup (string_value);
if (!button_layout_equal (&button_layout, &new_layout))
{
button_layout = new_layout;
emit_changed (META_PREF_BUTTON_LAYOUT);
}
emit_changed (META_PREF_BUTTON_LAYOUT);
}
static gboolean
......@@ -1618,10 +1591,10 @@ meta_prefs_change_workspace_name (int num,
g_variant_builder_end (&builder));
}
void
meta_prefs_get_button_layout (MetaButtonLayout *button_layout_p)
const gchar *
meta_prefs_get_button_layout (void)
{
*button_layout_p = button_layout;
return button_layout;
}
gboolean
......
......@@ -115,7 +115,7 @@ const char* meta_prefs_get_window_screenshot_command (void);
const char* meta_prefs_get_terminal_command (void);
void meta_prefs_get_button_layout (MetaButtonLayout *button_layout);
const gchar* meta_prefs_get_button_layout (void);
/* Double, right, middle click can be configured to any titlebar meta-action */
GDesktopTitlebarAction meta_prefs_get_action_double_click_titlebar (void);
......
......@@ -159,6 +159,7 @@ gboolean meta_ui_window_should_not_cause_focus (Display *xdisplay,
Window xwindow);
void meta_ui_reload_theme (void);
void meta_ui_update_button_layout (void);
/* Not a real key symbol but means "key above the tab key"; this is
* used as the default keybinding for cycle_group.
......
......@@ -412,7 +412,6 @@ meta_frames_calc_geometry (MetaFrames *frames,
int width, height;
MetaFrameFlags flags;
MetaFrameType type;
MetaButtonLayout button_layout;
meta_core_get (frames->xdisplay, frame->xwindow,
META_CORE_GET_CLIENT_WIDTH, &width,
......@@ -421,10 +420,8 @@ meta_frames_calc_geometry (MetaFrames *frames,
META_CORE_GET_FRAME_TYPE, &type,
META_CORE_GET_END);
meta_prefs_get_button_layout (&button_layout);
meta_theme_calc_geometry (meta_ui_get_theme (), frame->theme_variant,
type, flags, width, height, &button_layout, fgeom);
type, flags, width, height, fgeom);
}
MetaFrames*
......@@ -2284,7 +2281,6 @@ meta_frames_paint (MetaFrames *frames,
MetaButtonState button_states[META_BUTTON_TYPE_LAST];
Window grab_frame;
int i;
MetaButtonLayout button_layout;
MetaGrabOp grab_op;
for (i = 0; i < META_BUTTON_TYPE_LAST; i++)
......@@ -2395,11 +2391,9 @@ meta_frames_paint (MetaFrames *frames,
META_CORE_GET_CLIENT_HEIGHT, &h,
META_CORE_GET_END);
meta_prefs_get_button_layout (&button_layout);
meta_theme_draw_frame (meta_ui_get_theme (), frame->theme_variant,
cr, type, flags, w, h, frame->title,
&button_layout, button_states, mini_icon, icon);
button_states, mini_icon, icon);
}
static gboolean
......
......@@ -729,6 +729,8 @@ load_theme (MetaThemeType theme_type,
gboolean compositing_manager;
const PangoFontDescription *titlebar_font;
GError *error;
const gchar *button_layout;
gboolean invert;
theme = meta_theme_new (theme_type);
......@@ -748,6 +750,11 @@ load_theme (MetaThemeType theme_type,
return NULL;
}
button_layout = meta_prefs_get_button_layout ();
invert = meta_ui_get_direction() == META_UI_DIRECTION_RTL;
meta_theme_set_button_layout (theme, button_layout, invert);
return theme;
}
......@@ -776,6 +783,18 @@ meta_ui_reload_theme (void)
meta_invalidate_default_icons ();
}
void
meta_ui_update_button_layout (void)
{
const gchar *button_layout;
gboolean invert;
button_layout = meta_prefs_get_button_layout ();
invert = meta_ui_get_direction() == META_UI_DIRECTION_RTL;
meta_theme_set_button_layout (meta_current_theme, button_layout, invert);
}
static void
meta_ui_accelerator_parse (const char *accel,
guint *keysym,
......
......@@ -62,7 +62,6 @@ struct _ThemeViewerWindow
MetaFrameBorders borders;
MetaButtonLayout button_layout;
MetaButtonState button_states[META_BUTTON_TYPE_LAST];
gboolean button_pressed;
......@@ -186,7 +185,7 @@ benchmark_draw_time (ThemeViewerWindow *window,
meta_theme_draw_frame (theme, window->theme_variant, cr,
window->frame_type, window->frame_flags,
width, height, "Benchmark",
&window->button_layout, window->button_states,
window->button_states,
window->mini_icon, window->icon);
cairo_destroy (cr);
......@@ -348,7 +347,7 @@ update_button_state (GtkWidget *widget,
meta_theme_calc_geometry (window->theme, window->theme_variant,
window->frame_type, window->frame_flags,
width, height, &window->button_layout, &fgeom);
width, height, &fgeom);
x -= PADDING;
y -= PADDING;
......@@ -408,8 +407,12 @@ update_button_layout (ThemeViewerWindow *window)
const gchar *text;
gint i;
if (!window->theme)
return;
text = gtk_entry_get_text (GTK_ENTRY (window->button_layout_entry));
window->button_layout = meta_button_layout_new (text, FALSE);
meta_theme_set_button_layout (window->theme, text, FALSE);
for (i = 0; i < META_BUTTON_TYPE_LAST; i++)
window->button_states[i] = META_BUTTON_STATE_NORMAL;
......@@ -775,7 +778,7 @@ theme_box_draw_cb (GtkWidget *widget,
meta_theme_draw_frame (window->theme, window->theme_variant, cr,
window->frame_type, window->frame_flags,
client_width, client_height, "Metacity Theme Viewer",
&window->button_layout, window->button_states,
window->button_states,
window->mini_icon, window->icon);
return TRUE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment