Commit ff8f30ff authored by Alberts Muktupāvels's avatar Alberts Muktupāvels
Browse files

desktop: add icon size setting

parent a07a5e19
......@@ -3,10 +3,16 @@ NULL =
overridedir = $(gsettingsschemadir)
override_DATA = 00_gnome-flashback.gschema.override
gsettings_ENUM_NAMESPACE = org.gnome.gnome-flashback.desktop
gsettings_ENUM_FILES = \
$(top_srcdir)/gnome-flashback/libdesktop/gf-desktop-enums.h \
$(NULL)
gsettings_SCHEMAS = \
org.gnome.gnome-flashback.gschema.xml \
org.gnome.gnome-flashback.desktop.gschema.xml \
org.gnome.gnome-flashback.desktop.background.gschema.xml \
org.gnome.gnome-flashback.desktop.icons.gschema.xml \
org.gnome.gnome-flashback.input-sources.gschema.xml \
$(NULL)
......
......@@ -13,5 +13,6 @@
</key>
<child schema="org.gnome.gnome-flashback.desktop.background" name="background" />
<child schema="org.gnome.gnome-flashback.desktop.icons" name="icons" />
</schema>
</schemalist>
<schemalist gettext-domain="gnome-flashback">
<schema id="org.gnome.gnome-flashback.desktop.icons" path="/org/gnome/gnome-flashback/desktop/icons/">
<key name="icon-size" enum="org.gnome.gnome-flashback.desktop.GfIconSize">
<default>"48px"</default>
<summary>Icon size</summary>
<description>The size of desktop icons.</description>
</key>
</schema>
</schemalist>
......@@ -18,6 +18,7 @@ libdesktop_la_CFLAGS = \
libdesktop_la_SOURCES = \
gf-background.c \
gf-background.h \
gf-desktop-enums.h \
gf-desktop-window.c \
gf-desktop-window.h \
gf-desktop.c \
......@@ -26,6 +27,7 @@ libdesktop_la_SOURCES = \
gf-icon-view.h \
gf-monitor-view.c \
gf-monitor-view.h \
$(BUILT_SOURCES) \
$(NULL)
libdesktop_la_LDFLAGS = \
......@@ -37,4 +39,30 @@ libdesktop_la_LIBADD = \
$(DESKTOP_LIBS) \
$(NULL)
ENUM_TYPES = \
$(srcdir)/gf-desktop-enums.h \
$(NULL)
gf-desktop-enum-types.c: gf-desktop-enum-types.c.in gf-desktop-enum-types.h $(ENUM_TYPES)
$(AM_V_GEN) $(GLIB_MKENUMS) --template $(srcdir)/gf-desktop-enum-types.c.in $(ENUM_TYPES) > \
gf-desktop-enum-types.c.tmp && mv gf-desktop-enum-types.c.tmp gf-desktop-enum-types.c
gf-desktop-enum-types.h: gf-desktop-enum-types.h.in $(ENUM_TYPES)
$(AM_V_GEN) $(GLIB_MKENUMS) --template $(srcdir)/gf-desktop-enum-types.h.in $(ENUM_TYPES) > \
gf-desktop-enum-types.h.tmp && mv gf-desktop-enum-types.h.tmp gf-desktop-enum-types.h
BUILT_SOURCES = \
gf-desktop-enum-types.c \
gf-desktop-enum-types.h \
$(NULL)
EXTRA_DIST = \
gf-desktop-enum-types.c.in \
gf-desktop-enum-types.h.in \
$(NULL)
CLEANFILES = \
$(BUILT_SOURCES) \
$(NULL)
-include $(top_srcdir)/git.mk
/*** BEGIN file-header ***/
#include "config.h"
#include "gf-desktop-enum-types.h"
/*** END file-header ***/
/*** BEGIN file-production ***/
#include "@filename@"
/*** END file-production ***/
/*** BEGIN value-header ***/
GType
@enum_name@_get_type (void)
{
static volatile gsize g_enum_type_id;
static const G@Type@Value values[] =
{
/*** END value-header ***/
/*** BEGIN value-production ***/
{ @VALUENAME@, "@VALUENAME@", "@valuenick@" },
/*** END value-production ***/
/*** BEGIN value-tail ***/
{ 0, NULL, NULL }
};
if (g_once_init_enter (&g_enum_type_id))
{
const gchar *string;
GType id;
string = g_intern_static_string ("@EnumName@");
id = g_@type@_register_static (string, values);
g_once_init_leave (&g_enum_type_id, id);
}
return g_enum_type_id;
}
/*** END value-tail ***/
/*** BEGIN file-header ***/
#ifndef GF_DESKTOP_ENUM_TYPES_H
#define GF_DESKTOP_ENUM_TYPES_H
#include <glib-object.h>
G_BEGIN_DECLS
/*** END file-header ***/
/*** BEGIN value-header ***/
GType @enum_name@_get_type (void) G_GNUC_CONST;
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
/*** END value-header ***/
/*** BEGIN file-tail ***/
G_END_DECLS
#endif
/*** END file-tail ***/
/*
* Copyright (C) 2019 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 3 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 GF_DESKTOP_ENUMS_H
#define GF_DESKTOP_ENUMS_H
#include <glib.h>
G_BEGIN_DECLS
typedef enum
{
GF_ICON_SIZE_16PX = 16,
GF_ICON_SIZE_22PX = 22,
GF_ICON_SIZE_24PX = 24,
GF_ICON_SIZE_32PX = 32,
GF_ICON_SIZE_48PX = 48,
GF_ICON_SIZE_64PX = 64,
GF_ICON_SIZE_72PX = 72,
GF_ICON_SIZE_96PX = 96,
GF_ICON_SIZE_128PX = 128
} GfIconSize;
G_END_DECLS
#endif
......@@ -18,12 +18,15 @@
#include "config.h"
#include "gf-icon-view.h"
#include "gf-desktop-enum-types.h"
#include "gf-monitor-view.h"
struct _GfIconView
{
GtkEventBox parent;
GSettings *settings;
GtkWidget *fixed;
};
......@@ -71,19 +74,54 @@ workarea_cb (GdkMonitor *monitor,
gtk_fixed_move (GTK_FIXED (self->fixed), view, workarea.x, workarea.y);
}
static gboolean
enum_to_uint (GValue *value,
GVariant *variant,
gpointer user_data)
{
const char *nick;
GEnumClass *enum_class;
GEnumValue *enum_value;
nick = g_variant_get_string (variant, NULL);
enum_class = g_type_class_ref (GF_TYPE_ICON_SIZE);
enum_value = g_enum_get_value_by_nick (enum_class, nick);
g_type_class_unref (enum_class);
if (enum_value != NULL)
{
g_value_set_uint (value, enum_value->value);
return TRUE;
}
return FALSE;
}
static void
create_monitor_view (GfIconView *self,
GdkMonitor *monitor)
{
guint icon_size;
GdkRectangle workarea;
GtkWidget *view;
icon_size = g_settings_get_enum (self->settings, "icon-size");
gdk_monitor_get_workarea (monitor, &workarea);
view = gf_monitor_view_new (monitor);
view = gf_monitor_view_new (monitor, icon_size);
gtk_fixed_put (GTK_FIXED (self->fixed), view, workarea.x, workarea.y);
gtk_widget_show (view);
g_settings_bind_with_mapping (self->settings, "icon-size",
view, "icon-size",
G_SETTINGS_BIND_GET,
enum_to_uint,
NULL,
self,
NULL);
g_signal_connect_object (monitor, "notify::workarea",
G_CALLBACK (workarea_cb),
self, 0);
......@@ -111,9 +149,26 @@ monitor_removed_cb (GdkDisplay *display,
gtk_widget_destroy (view);
}
static void
gf_icon_view_dispose (GObject *object)
{
GfIconView *self;
self = GF_ICON_VIEW (object);
g_clear_object (&self->settings);
G_OBJECT_CLASS (gf_icon_view_parent_class)->dispose (object);
}
static void
gf_icon_view_class_init (GfIconViewClass *self_class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (self_class);
object_class->dispose = gf_icon_view_dispose;
}
static void
......@@ -123,6 +178,8 @@ gf_icon_view_init (GfIconView *self)
int n_monitors;
int i;
self->settings = g_settings_new ("org.gnome.gnome-flashback.desktop.icons");
self->fixed = gtk_fixed_new ();
gtk_container_add (GTK_CONTAINER (self), self->fixed);
gtk_widget_show (self->fixed);
......
......@@ -24,6 +24,8 @@ struct _GfMonitorView
GdkMonitor *monitor;
guint icon_size;
int width;
int height;
};
......@@ -34,6 +36,8 @@ enum
PROP_MONITOR,
PROP_ICON_SIZE,
LAST_PROP
};
......@@ -41,6 +45,18 @@ static GParamSpec *view_properties[LAST_PROP] = { NULL };
G_DEFINE_TYPE (GfMonitorView, gf_monitor_view, GTK_TYPE_FIXED)
static void
set_icon_size (GfMonitorView *self,
guint icon_size)
{
if (self->icon_size == icon_size)
return;
self->icon_size = icon_size;
gtk_widget_queue_resize (GTK_WIDGET (self));
}
static void
workarea_cb (GdkMonitor *monitor,
GParamSpec *pspec,
......@@ -101,6 +117,10 @@ gf_monitor_view_set_property (GObject *object,
self->monitor = g_value_dup_object (value);
break;
case PROP_ICON_SIZE:
set_icon_size (self, g_value_get_uint (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -151,6 +171,15 @@ install_properties (GObjectClass *object_class)
G_PARAM_WRITABLE |
G_PARAM_STATIC_STRINGS);
view_properties[PROP_ICON_SIZE] =
g_param_spec_uint ("icon-size",
"icon-size",
"icon-size",
16, 128, 48,
G_PARAM_CONSTRUCT |
G_PARAM_WRITABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, view_properties);
}
......@@ -180,10 +209,12 @@ gf_monitor_view_init (GfMonitorView *self)
}
GtkWidget *
gf_monitor_view_new (GdkMonitor *monitor)
gf_monitor_view_new (GdkMonitor *monitor,
guint icon_size)
{
return g_object_new (GF_TYPE_MONITOR_VIEW,
"monitor", monitor,
"icon-size", icon_size,
NULL);
}
......
......@@ -25,7 +25,8 @@ G_BEGIN_DECLS
#define GF_TYPE_MONITOR_VIEW (gf_monitor_view_get_type ())
G_DECLARE_FINAL_TYPE (GfMonitorView, gf_monitor_view, GF, MONITOR_VIEW, GtkFixed)
GtkWidget *gf_monitor_view_new (GdkMonitor *monitor);
GtkWidget *gf_monitor_view_new (GdkMonitor *monitor,
guint icon_size);
GdkMonitor *gf_monitor_view_get_monitor (GfMonitorView *self);
......
......@@ -9,6 +9,7 @@ data/directories/X-GNOME-Flashback-Settings-System.directory.desktop.in
data/schemas/org.gnome.gnome-flashback.gschema.xml
data/schemas/org.gnome.gnome-flashback.desktop.gschema.xml
data/schemas/org.gnome.gnome-flashback.desktop.background.gschema.xml
data/schemas/org.gnome.gnome-flashback.desktop.icons.gschema.xml
data/schemas/org.gnome.gnome-flashback.input-sources.gschema.xml
data/ui/gf-confirm-display-change-dialog.ui
data/xsessions/gnome-flashback-compiz.desktop.in.in
......
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