Commit 124078d4 authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

panel-toplevel: avoid deprecated GtkArrow

parent 9c45e43f
@import url("resource:///org/gnome/panel/Adwaita.css");
@import url("resource:///org/gnome/gnome-panel/theme/common.css");
gp-arrow-button {
border: 1px solid #1c1f1f;
border-radius: 3px;
background-image: linear-gradient(to bottom, #343a3a, #2f3434 60%, #2a2f2f);
margin: 2px;
}
gp-arrow-button:hover {
background-image: linear-gradient(to bottom, #3b4242, #343a3a 60%, #2f3434);
}
gp-arrow-button:active {
background-image: linear-gradient(to bottom, #232727, #2d3232);
}
@import url("resource:///org/gnome/panel/Adwaita.css");
@import url("resource:///org/gnome/gnome-panel/theme/common.css");
gp-arrow-button {
border: 1px solid #9d9d99;
border-radius: 3px;
background-image: linear-gradient(to bottom, #e8e8e7, #dededd 60%, #cfcfcd);
margin: 2px;
}
gp-arrow-button:hover {
background-image: linear-gradient(to bottom, #f7f7f7, #e8e8e7 60%, #dededd);
}
gp-arrow-button:active {
background-image: linear-gradient(to bottom, #c8c8c5, #dcdcda);
}
@import url("resource:///org/gnome/panel/HighContrast.css");
@import url("resource:///org/gnome/gnome-panel/theme/common.css");
gp-arrow-button {
border: 2px solid #7f7f7f;
border-radius: 3px;
background-color: #ffffff;
margin: 2px;
}
gp-arrow-button:hover {
background-color: #ffffff;
}
gp-arrow-button:active {
background-color: #000000;
}
/* This file will be included in both themes - Adwaita and HighContrast. */
gp-arrow-button {
min-width: 20px;
min-height: 0px;
}
.vertical gp-arrow-button {
min-width: 0px;
min-height: 20px;
}
......@@ -13,6 +13,8 @@ bin_PROGRAMS = \
panel_sources = \
$(gnome_panel_BUILT_SOURCES) \
gp-arrow-button.c \
gp-arrow-button.h \
main.c \
panel-widget.c \
button-widget.c \
......
/*
* Copyright (C) 2015 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <glib/gi18n.h>
#include "gp-arrow-button.h"
struct _GpArrowButton
{
GtkButton parent;
GtkArrowType arrow_type;
gboolean arrow_visible;
GtkWidget *arrow;
};
enum
{
PROP_0,
PROP_ARROW_TYPE,
PROP_ARROW_VISIBLE,
LAST_PROP
};
static GParamSpec *properties[LAST_PROP] = { NULL };
G_DEFINE_TYPE (GpArrowButton, gp_arrow_button, GTK_TYPE_BUTTON)
static void
set_arrow_visible (GpArrowButton *button,
gboolean arrow_visible)
{
if (button->arrow_visible == arrow_visible)
return;
button->arrow_visible = arrow_visible;
gtk_widget_set_visible (button->arrow, arrow_visible);
}
static void
set_arrow_type (GpArrowButton *button,
GtkArrowType arrow_type)
{
const gchar *icon_name;
GtkImage *image;
if (button->arrow_type == arrow_type)
return;
button->arrow_type = arrow_type;
switch (arrow_type)
{
case GTK_ARROW_UP:
icon_name = "pan-up-symbolic";
break;
case GTK_ARROW_DOWN:
icon_name = "pan-down-symbolic";
break;
case GTK_ARROW_LEFT:
icon_name = "pan-start-symbolic";
break;
case GTK_ARROW_RIGHT:
icon_name = "pan-end-symbolic";
break;
case GTK_ARROW_NONE:
default:
icon_name = NULL;
break;
}
image = GTK_IMAGE (button->arrow);
if (icon_name == NULL)
{
gtk_image_clear (image);
set_arrow_visible (button, FALSE);
return;
}
gtk_image_set_from_icon_name (image, icon_name, GTK_ICON_SIZE_MENU);
}
static void
gp_arrow_button_constructed (GObject *object)
{
GtkWidget *widget;
AtkObject *atk;
G_OBJECT_CLASS (gp_arrow_button_parent_class)->constructed (object);
widget = GTK_WIDGET (object);
atk = gtk_widget_get_accessible (widget);
atk_object_set_name (atk, _("Hide Panel"));
}
static void
gp_arrow_button_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GpArrowButton *button;
button = GP_ARROW_BUTTON (object);
switch (property_id)
{
case PROP_ARROW_TYPE:
g_value_set_enum (value, button->arrow_type);
break;
case PROP_ARROW_VISIBLE:
g_value_set_boolean (value, button->arrow_visible);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gp_arrow_button_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GpArrowButton *button;
button = GP_ARROW_BUTTON (object);
switch (property_id)
{
case PROP_ARROW_TYPE:
set_arrow_type (button, g_value_get_enum (value));
break;
case PROP_ARROW_VISIBLE:
set_arrow_visible (button, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gp_arrow_button_class_init (GpArrowButtonClass *button_class)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = G_OBJECT_CLASS (button_class);
widget_class = GTK_WIDGET_CLASS (button_class);
object_class->constructed = gp_arrow_button_constructed;
object_class->get_property = gp_arrow_button_get_property;
object_class->set_property = gp_arrow_button_set_property;
properties[PROP_ARROW_TYPE] =
g_param_spec_enum ("arrow-type", "arrow-type", "arrow-type",
GTK_TYPE_ARROW_TYPE, GTK_ARROW_NONE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
properties[PROP_ARROW_VISIBLE] =
g_param_spec_boolean ("arrow-visible", "arrow-visible", "arrow-visible",
TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, properties);
gtk_widget_class_set_css_name (widget_class, "gp-arrow-button");
}
static void
gp_arrow_button_init (GpArrowButton *button)
{
button->arrow = gtk_image_new ();
button->arrow_type = GTK_ARROW_NONE;
gtk_container_add (GTK_CONTAINER (button), button->arrow);
}
GtkWidget *
gp_arrow_button_new (GtkArrowType arrow_type)
{
return g_object_new (GP_TYPE_ARROW_BUTTON,
"arrow-type", arrow_type,
NULL);
}
GtkArrowType
gp_arrow_button_get_arrow_type (GpArrowButton *button)
{
return button->arrow_type;
}
/*
* Copyright (C) 2015 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GP_ARROW_BUTTON_H
#define GP_ARROW_BUTTON_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GP_TYPE_ARROW_BUTTON gp_arrow_button_get_type ()
G_DECLARE_FINAL_TYPE (GpArrowButton, gp_arrow_button,
GP, ARROW_BUTTON, GtkButton)
GtkWidget *gp_arrow_button_new (GtkArrowType arrow_type);
GtkArrowType gp_arrow_button_get_arrow_type (GpArrowButton *button);
G_END_DECLS
#endif
......@@ -35,6 +35,7 @@
#include <libpanel-util/panel-glib.h>
#include "gp-arrow-button.h"
#include "panel-frame.h"
#include "panel-xutils.h"
#include "panel-multiscreen.h"
......@@ -59,7 +60,6 @@ G_DEFINE_TYPE (PanelToplevel, panel_toplevel, GTK_TYPE_WINDOW)
#define MINIMUM_WIDTH 100
#define MAXIMUM_SIZE_SCREEN_RATIO 5
#define SNAP_TOLERANCE_FACTOR 6
#define DEFAULT_ARROW_SIZE 20
#define HANDLE_SIZE 10
typedef enum {
......@@ -224,8 +224,7 @@ enum {
PROP_AUTOHIDE_SIZE,
PROP_ANIMATE,
PROP_ANIMATION_SPEED,
PROP_BUTTONS_ENABLED,
PROP_ARROWS_ENABLED
PROP_BUTTONS_ENABLED
};
static guint toplevel_signals [LAST_SIGNAL] = { 0 };
......@@ -1219,10 +1218,10 @@ panel_toplevel_hide_button_clicked (PanelToplevel *toplevel,
return;
ltr = gtk_widget_get_direction (GTK_WIDGET (toplevel)) == GTK_TEXT_DIR_LTR;
arrow_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "arrow-type"));
arrow_type = gp_arrow_button_get_arrow_type (GP_ARROW_BUTTON (button));
if (toplevel->priv->state == PANEL_STATE_NORMAL) {
GtkDirectionType direction = -1;
GtkDirectionType direction;
switch (arrow_type) {
case GTK_ARROW_UP:
......@@ -1237,6 +1236,7 @@ panel_toplevel_hide_button_clicked (PanelToplevel *toplevel,
case GTK_ARROW_RIGHT:
direction = ltr ? GTK_DIR_RIGHT : GTK_DIR_LEFT;
break;
case GTK_ARROW_NONE:
default:
g_assert_not_reached ();
break;
......@@ -1254,45 +1254,8 @@ panel_toplevel_add_hide_button (PanelToplevel *toplevel,
int top)
{
GtkWidget *button;
AtkObject *obj;
GtkWidget *arrow;
int arrow_size;
button = gtk_button_new ();
obj = gtk_widget_get_accessible (button);
atk_object_set_name (obj, _("Hide Panel"));
gtk_widget_set_can_default (button, FALSE);
gtk_widget_style_get (GTK_WIDGET (toplevel),
"arrow-size", &arrow_size,
NULL);
switch (arrow_type) {
case GTK_ARROW_UP:
gtk_widget_set_size_request (button, -1, arrow_size);
break;
case GTK_ARROW_DOWN:
gtk_widget_set_size_request (button, -1, arrow_size);
break;
case GTK_ARROW_LEFT:
gtk_widget_set_size_request (button, arrow_size, -1);
break;
case GTK_ARROW_RIGHT:
gtk_widget_set_size_request (button, arrow_size, -1);
break;
default:
g_assert_not_reached ();
break;
}
arrow = gtk_arrow_new (arrow_type, GTK_SHADOW_NONE);
gtk_misc_set_padding (GTK_MISC (arrow), 0, 0);
gtk_container_add (GTK_CONTAINER (button), arrow);
gtk_widget_show (arrow);
g_object_set_data (G_OBJECT (button),
"arrow-type",
GINT_TO_POINTER (arrow_type));
button = gp_arrow_button_new (arrow_type);
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (panel_toplevel_hide_button_clicked), toplevel);
......@@ -1347,35 +1310,15 @@ panel_toplevel_update_hide_buttons (PanelToplevel *toplevel)
}
if (toplevel->priv->arrows_enabled) {
int arrow_size;
gtk_widget_show (gtk_bin_get_child (GTK_BIN (toplevel->priv->hide_button_top)));
gtk_widget_show (gtk_bin_get_child (GTK_BIN (toplevel->priv->hide_button_bottom)));
gtk_widget_show (gtk_bin_get_child (GTK_BIN (toplevel->priv->hide_button_left)));
gtk_widget_show (gtk_bin_get_child (GTK_BIN (toplevel->priv->hide_button_right)));
gtk_widget_style_get (GTK_WIDGET (toplevel),
"arrow-size", &arrow_size,
NULL);
gtk_widget_set_size_request (toplevel->priv->hide_button_top,
-1, arrow_size);
gtk_widget_set_size_request (toplevel->priv->hide_button_bottom,
-1, arrow_size);
gtk_widget_set_size_request (toplevel->priv->hide_button_left,
arrow_size, -1);
gtk_widget_set_size_request (toplevel->priv->hide_button_right,
arrow_size, -1);
} else {
gtk_widget_hide (gtk_bin_get_child (GTK_BIN (toplevel->priv->hide_button_top)));
gtk_widget_hide (gtk_bin_get_child (GTK_BIN (toplevel->priv->hide_button_bottom)));
gtk_widget_hide (gtk_bin_get_child (GTK_BIN (toplevel->priv->hide_button_left)));
gtk_widget_hide (gtk_bin_get_child (GTK_BIN (toplevel->priv->hide_button_right)));
gtk_widget_set_size_request (toplevel->priv->hide_button_top, -1, -1);
gtk_widget_set_size_request (toplevel->priv->hide_button_bottom, -1, -1);
gtk_widget_set_size_request (toplevel->priv->hide_button_left, -1, -1);
gtk_widget_set_size_request (toplevel->priv->hide_button_right, -1, -1);
}
}
......@@ -3644,9 +3587,6 @@ panel_toplevel_set_property (GObject *object,
case PROP_BUTTONS_ENABLED:
panel_toplevel_set_enable_buttons (toplevel, g_value_get_boolean (value));
break;
case PROP_ARROWS_ENABLED:
panel_toplevel_set_enable_arrows (toplevel, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -3726,9 +3666,6 @@ panel_toplevel_get_property (GObject *object,
case PROP_BUTTONS_ENABLED:
g_value_set_boolean (value, toplevel->priv->buttons_enabled);
break;
case PROP_ARROWS_ENABLED:
g_value_set_boolean (value, toplevel->priv->arrows_enabled);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -4048,27 +3985,6 @@ panel_toplevel_class_init (PanelToplevelClass *klass)
TRUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_ARROWS_ENABLED,
g_param_spec_boolean (
"arrows-enabled",
"Arrows Enabled",
"Enable arrows on hide/show buttons",
TRUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
gtk_widget_class_install_style_property (
widget_class,
g_param_spec_int (
"arrow-size",
"Arrow Size",
"The size of the arrows on the hide/show buttons",
0,
G_MAXINT,
DEFAULT_ARROW_SIZE,
G_PARAM_READABLE));
toplevel_signals [HIDE_SIGNAL] =
g_signal_new ("hiding",
G_TYPE_FROM_CLASS (gobject_class),
......@@ -4492,11 +4408,27 @@ panel_toplevel_bind_gsettings (PanelToplevel *toplevel)
"buttons-enabled",
G_SETTINGS_BIND_DEFAULT|G_SETTINGS_BIND_NO_SENSITIVITY);
/* FIXME: should be in panel_toplevel_add_hide_button */
g_settings_bind (toplevel->priv->settings,
PANEL_TOPLEVEL_ENABLE_ARROWS_KEY,
toplevel,
"arrows-enabled",
G_SETTINGS_BIND_DEFAULT|G_SETTINGS_BIND_NO_SENSITIVITY);
PANEL_TOPLEVEL_ENABLE_ARROWS_KEY,
toplevel->priv->hide_button_top, "arrow-visible",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
g_settings_bind (toplevel->priv->settings,
PANEL_TOPLEVEL_ENABLE_ARROWS_KEY,
toplevel->priv->hide_button_bottom, "arrow-visible",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
g_settings_bind (toplevel->priv->settings,
PANEL_TOPLEVEL_ENABLE_ARROWS_KEY,
toplevel->priv->hide_button_left, "arrow-visible",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
g_settings_bind (toplevel->priv->settings,
PANEL_TOPLEVEL_ENABLE_ARROWS_KEY,
toplevel->priv->hide_button_right, "arrow-visible",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
}
static void
......@@ -5202,32 +5134,6 @@ panel_toplevel_get_enable_buttons (PanelToplevel *toplevel)
return toplevel->priv->buttons_enabled;
}
void
panel_toplevel_set_enable_arrows (PanelToplevel *toplevel,
gboolean enable_arrows)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
enable_arrows = enable_arrows != FALSE;
if (toplevel->priv->arrows_enabled == enable_arrows)
return;
toplevel->priv->arrows_enabled = enable_arrows;
panel_toplevel_update_hide_buttons (toplevel);
g_object_notify (G_OBJECT (toplevel), "arrows-enabled");
}
gboolean
panel_toplevel_get_enable_arrows (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
return toplevel->priv->arrows_enabled;
}
void
panel_toplevel_rotate (PanelToplevel *toplevel,
gboolean clockwise)
......
......@@ -146,9 +146,6 @@ PanelAnimationSpeed panel_toplevel_get_animation_speed (PanelToplevel
void panel_toplevel_set_enable_buttons (PanelToplevel *toplevel,
gboolean enable_buttons);
gboolean panel_toplevel_get_enable_buttons (PanelToplevel *toplevel);
void panel_toplevel_set_enable_arrows (PanelToplevel *toplevel,
gboolean enable_arrows);
gboolean panel_toplevel_get_enable_arrows (PanelToplevel *toplevel);
void panel_toplevel_update_edges (PanelToplevel *toplevel);
gboolean panel_toplevel_is_last (PanelToplevel *toplevel);
......
......@@ -41,6 +41,7 @@ gnome-panel/applet.c
gnome-panel/button-widget.c
gnome-panel/gnome-desktop-item-edit.c
gnome-panel/gnome-panel.desktop.in.in
gnome-panel/gp-arrow-button.c
gnome-panel/launcher.c
gnome-panel/libpanel-util/panel-error.c
gnome-panel/libpanel-util/panel-icon-chooser.c
......
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