Handle gtk-cursor-theme-size.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Wed, 28 Jul 2010 15:53:44 +0000 (23:53 +0800)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Wed, 28 Jul 2010 15:53:44 +0000 (23:53 +0800)
data/ui/lxappearance.glade
src/cursor-theme.c
src/icon-theme.c
src/lxappearance2.c
src/lxappearance2.h

index 30f5142..ed57d5c 100644 (file)
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
-  <object class="GtkListStore" id="tb_icon_size_store">
-    <columns>
-      <!-- column-name name -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Same as menu items</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Small toolbar icon</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Large toolbar icon</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Same as buttons</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Same as drag icons</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Same as dialogs</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="tb_style_store">
-    <columns>
-      <!-- column-name item -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Icons only</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Text only</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Text below icons</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Text beside icons</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkImage" id="image5">
-    <property name="visible">True</property>
-    <property name="stock">gtk-remove</property>
-  </object>
-  <object class="GtkImage" id="image4">
-    <property name="visible">True</property>
-    <property name="stock">gtk-add</property>
-  </object>
-  <object class="GtkImage" id="image3">
-    <property name="visible">True</property>
-    <property name="stock">gtk-remove</property>
-  </object>
-  <object class="GtkImage" id="image2">
-    <property name="visible">True</property>
-    <property name="stock">gtk-add</property>
-  </object>
-  <object class="GtkListStore" id="icon_demo_store">
-    <columns>
-      <!-- column-name icon-name -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">user-home</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">user-desktop</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">folder</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">folder-remote</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">user-trash</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">x-office-document</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">application-x-executable</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">image-x-generic</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">text-x-generic</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">text-html</col>
-      </row>
-    </data>
+  <object class="GtkAdjustment" id="cursor_size_adj">
+    <property name="upper">138</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+    <property name="page_size">10</property>
   </object>
   <object class="GtkDialog" id="dlg">
     <property name="border_width">5</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkFontButton" id="fontbutton1">
+                          <object class="GtkFontButton" id="default_font">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
                 <child>
                   <object class="GtkVBox" id="vbox11">
                     <property name="visible">True</property>
+                    <property name="spacing">6</property>
                     <child>
                       <object class="GtkLabel" id="label7">
                         <property name="visible">True</property>
                           <object class="GtkIconView" id="cursor_demo_view">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
-                            <child>
-                              <object class="GtkCellRendererPixbuf" id="cellrenderertext4">
-                                <property name="stock_size">6</property>
-                              </object>
-                              <attributes>
-                                <attribute name="icon-name">0</attribute>
-                              </attributes>
-                            </child>
                           </object>
                         </child>
                       </object>
                       </packing>
                     </child>
                     <child>
-                      <placeholder/>
+                      <object class="GtkLabel" id="label26">
+                        <property name="visible">True</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Size of cursors</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkHBox" id="hbox5">
+                        <property name="visible">True</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkLabel" id="label29">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Smaller</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkHScale" id="cursor_size">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="update_policy">delayed</property>
+                            <property name="adjustment">cursor_size_adj</property>
+                            <property name="digits">0</property>
+                            <property name="value_pos">left</property>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label27">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Bigger</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">3</property>
+                      </packing>
                     </child>
                   </object>
                   <packing>
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="close">
-                <property name="label">gtk-close</property>
+              <object class="GtkButton" id="apply">
+                <property name="label">gtk-apply</property>
                 <property name="visible">True</property>
+                <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="apply">
-                <property name="label">gtk-apply</property>
+              <object class="GtkButton" id="close">
+                <property name="label">gtk-close</property>
                 <property name="visible">True</property>
-                <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
     </child>
     <action-widgets>
       <action-widget response="1">about</action-widget>
-      <action-widget response="-7">close</action-widget>
       <action-widget response="-10">apply</action-widget>
+      <action-widget response="-7">close</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkListStore" id="icon_demo_store">
+    <columns>
+      <!-- column-name icon-name -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">user-home</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">user-desktop</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">folder</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">folder-remote</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">user-trash</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">x-office-document</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">application-x-executable</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">image-x-generic</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">text-x-generic</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">text-html</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkImage" id="image2">
+    <property name="visible">True</property>
+    <property name="stock">gtk-add</property>
+  </object>
+  <object class="GtkImage" id="image3">
+    <property name="visible">True</property>
+    <property name="stock">gtk-remove</property>
+  </object>
+  <object class="GtkImage" id="image4">
+    <property name="visible">True</property>
+    <property name="stock">gtk-add</property>
+  </object>
+  <object class="GtkImage" id="image5">
+    <property name="visible">True</property>
+    <property name="stock">gtk-remove</property>
+  </object>
+  <object class="GtkListStore" id="tb_style_store">
+    <columns>
+      <!-- column-name item -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Icons only</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Text only</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Text below icons</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Text beside icons</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="tb_icon_size_store">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Same as menu items</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Small toolbar icon</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Large toolbar icon</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Same as buttons</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Same as drag icons</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Same as dialogs</col>
+      </row>
+    </data>
+  </object>
 </interface>
index 960feca..889adc6 100644 (file)
  */
 
 #include "cursor-theme.h"
+#include "icon-theme.h"
 #include "lxappearance2.h"
+#include <gdk/gdkx.h>
 
-static GtkWidget* cursor_theme_view;
+static void update_cursor_demo()
+{
+    GtkListStore* store = gtk_list_store_new(1, GDK_TYPE_PIXBUF);
+    GdkCursorType types[] = {
+        GDK_LEFT_PTR,
+        GDK_HAND2,
+        GDK_WATCH,
+        GDK_FLEUR,
+        GDK_XTERM,
+        GDK_LEFT_SIDE,
+        GDK_TOP_LEFT_CORNER,
+        GDK_SB_H_DOUBLE_ARROW};
+    int i;
+    for(i = 0; i < G_N_ELEMENTS(types); ++i)
+    {
+        GtkTreeIter it;
+        GdkCursor* cursor = gdk_cursor_new(types[i]);
+        GdkPixbuf* pix = gdk_cursor_get_image(cursor);
+        gdk_cursor_unref(cursor);
+        gtk_list_store_insert_with_values(store, &it, -1, 0, pix, -1);
+        g_object_unref(pix);
+    }
+    gtk_icon_view_set_model(app.cursor_demo_view, GTK_TREE_MODEL(store));
+    g_object_unref(store);
+}
+
+static void on_cursor_theme_sel_changed(GtkTreeSelection* tree_sel, gpointer user_data)
+{
+    GtkTreeModel* model;
+    GtkTreeIter it;
+    if(gtk_tree_selection_get_selected(tree_sel, &model, &it))
+    {
+        IconTheme* theme;
+        gtk_tree_model_get(model, &it, 1, &theme, -1);
+        if(g_strcmp0(theme->name, app.cursor_theme))
+        {
+            g_free(app.cursor_theme);
+            app.cursor_theme = g_strdup(theme->name);
+            g_object_set(gtk_settings_get_default(), "gtk-cursor-theme-name", app.cursor_theme, NULL);
+
+            update_cursor_demo();
+            lxappearance_changed();
+        }
+    }
+}
+
+static void on_cursor_theme_size_changed(GtkRange* range, gpointer user_data)
+{
+    int size = (int)gtk_range_get_value(range);
+    if(size != app.cursor_theme_size)
+    {
+        app.cursor_theme_size = size;
+        g_object_set(gtk_settings_get_default(), "gtk-cursor-theme-size", size, NULL);
+
+        update_cursor_demo();
+        lxappearance_changed();
+    }
+}
 
 void cursor_theme_init(GtkBuilder* b)
 {
+    GtkTreeSelection* sel = gtk_tree_view_get_selection(app.cursor_theme_view);
     /* treeview and model are already set up in icon_theme_init() */
+    g_signal_connect(sel, "changed", G_CALLBACK(on_cursor_theme_sel_changed), NULL);
+
+    app.cursor_size_range = GTK_RANGE(gtk_builder_get_object(b, "cursor_size"));
+    gtk_range_set_value(app.cursor_size_range, app.cursor_theme_size);
+    g_signal_connect(app.cursor_size_range, "value-changed", G_CALLBACK(on_cursor_theme_size_changed), NULL);
 
+    app.cursor_demo_view = GTK_WIDGET(gtk_builder_get_object(b, "cursor_demo_view"));
+    gtk_icon_view_set_pixbuf_column(app.cursor_demo_view, 0);
+    update_cursor_demo();
 }
index 53fdd3e..2611ded 100644 (file)
@@ -136,6 +136,25 @@ static void icon_sizes_init(GtkBuilder* b)
     g_debug("%s", sizes_str);
 }
 
+static void on_icon_theme_sel_changed(GtkTreeSelection* tree_sel, gpointer user_data)
+{
+    GtkTreeModel* model;
+    GtkTreeIter it;
+    if(gtk_tree_selection_get_selected(tree_sel, &model, &it))
+    {
+        IconTheme* theme;
+        gtk_tree_model_get(model, &it, 1, &theme, -1);
+        if(g_strcmp0(theme->name, app.icon_theme))
+        {
+            g_free(app.icon_theme);
+            app.icon_theme = g_strdup(theme->name);
+            g_object_set(gtk_settings_get_default(), "gtk-icon-theme-name", app.icon_theme, NULL);
+
+            lxappearance_changed();
+        }
+    }
+}
+
 void icon_theme_init(GtkBuilder* b)
 {
     GSList* l;
@@ -187,6 +206,7 @@ void icon_theme_init(GtkBuilder* b)
         gtk_tree_view_scroll_to_cell(app.icon_theme_view, tp, NULL, FALSE, 0, 0);
         gtk_tree_path_free(tp);
     }
+    g_signal_connect(sel, "changed", G_CALLBACK(on_icon_theme_sel_changed), NULL);
 
     gtk_tree_view_set_model(app.cursor_theme_view, GTK_TREE_MODEL(app.cursor_theme_store));
     sel = gtk_tree_view_get_selection(app.cursor_theme_view);
index 1669e82..4f69f4d 100644 (file)
@@ -107,6 +107,7 @@ static void settings_init()
                 "gtk-theme-name", &app.widget_theme,
                 "gtk-icon-theme-name", &app.icon_theme,
                 "gtk-cursor-theme-name", &app.cursor_theme,
+                "gtk-cursor-theme-size", &app.cursor_theme_size,
                 "gtk-toolbar-style", &app.toolbar_style,
                 "gtk-toolbar-icon-size", &app.toolbar_icon_size,
                 NULL);
@@ -144,12 +145,6 @@ int main(int argc, char** argv)
     textdomain ( GETTEXT_PACKAGE );
 #endif
 
-    /* init threading support */
-    /*
-    g_thread_init(NULL);
-    gdk_threads_init();
-    */
-
     /* initialize GTK+ and parse the command line arguments */
     if( G_UNLIKELY( ! gtk_init_with_args( &argc, &argv, "", option_entries, GETTEXT_PACKAGE, &err ) ) )
     {
index 1289520..6a8ca86 100644 (file)
@@ -37,7 +37,9 @@ struct _LXAppearance
     GtkListStore* icon_theme_store;
 
     GtkWidget* cursor_theme_view;
+    GtkWidget* cursor_demo_view;
     GtkListStore* cursor_theme_store;
+    GtkWidget* cursor_size_range;
 
     GSList* icon_themes; /* a list of IconTheme struct */
 
@@ -47,6 +49,7 @@ struct _LXAppearance
     char* widget_theme;
     char* icon_theme;
     char* cursor_theme;
+    int cursor_theme_size;
     char* color_scheme;
     char* icon_sizes;
     int toolbar_style;