Bump version number.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Wed, 28 Jul 2010 17:55:25 +0000 (01:55 +0800)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Wed, 28 Jul 2010 17:55:25 +0000 (01:55 +0800)
Save config files correctly.

configure.ac
data/ui/lxappearance.glade
src/cursor-theme.c
src/lxappearance2.c
src/lxappearance2.h
src/widget-theme.c

index 81ec326..69eb510 100644 (file)
@@ -4,7 +4,7 @@
 prog_name = lxappearance2
 
 AC_PREREQ([2.63])
-AC_INIT([lxappearance2], [0.1.0], [http://lxde.org/])
+AC_INIT([lxappearance2], [0.2.0], [http://lxde.org/])
 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
 
 AC_CONFIG_HEADERS([config.h])
index ed57d5c..ab2182c 100644 (file)
@@ -3,6 +3,7 @@
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
   <object class="GtkAdjustment" id="cursor_size_adj">
+    <property name="lower">1</property>
     <property name="upper">138</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
             </child>
             <child>
               <object class="GtkVBox" id="vbox5">
-                <property name="visible">True</property>
                 <child>
                   <placeholder/>
                 </child>
                     </child>
                     <child>
                       <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>
                     </child>
                     <child>
                       <object class="GtkHBox" id="hbox5">
-                        <property name="visible">True</property>
                         <property name="spacing">12</property>
                         <child>
                           <object class="GtkLabel" id="label29">
             </child>
             <child>
               <object class="GtkVBox" id="vbox8">
-                <property name="visible">True</property>
                 <child>
                   <placeholder/>
                 </child>
index 889adc6..8a44fb2 100644 (file)
@@ -27,6 +27,7 @@
 static void update_cursor_demo()
 {
     GtkListStore* store = gtk_list_store_new(1, GDK_TYPE_PIXBUF);
+    GdkCursor* cursor;
     GdkCursorType types[] = {
         GDK_LEFT_PTR,
         GDK_HAND2,
@@ -36,11 +37,11 @@ static void update_cursor_demo()
         GDK_LEFT_SIDE,
         GDK_TOP_LEFT_CORNER,
         GDK_SB_H_DOUBLE_ARROW};
-    int i;
+    int i, n;
     for(i = 0; i < G_N_ELEMENTS(types); ++i)
     {
         GtkTreeIter it;
-        GdkCursor* cursor = gdk_cursor_new(types[i]);
+        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);
@@ -48,6 +49,20 @@ static void update_cursor_demo()
     }
     gtk_icon_view_set_model(app.cursor_demo_view, GTK_TREE_MODEL(store));
     g_object_unref(store);
+
+    /* gtk+ programs should reload named cursors correctly.
+     * However, if the cursor is inherited from the root window,
+     * gtk+ won't change it. So we need to update the cursor of root window.
+     * Unfortunately, this doesn't work for non-gtk+ programs.
+     * KDE programs seem to require special handling with XFixes */
+    cursor = gdk_cursor_new(GDK_LEFT_PTR);
+    i = gdk_display_get_n_screens(gdk_display_get_default());
+    while(--i >= 0)
+    {
+        GdkScreen* screen = gdk_display_get_screen(gdk_display_get_default(), i);
+        gdk_window_set_cursor(gdk_screen_get_root_window(screen), cursor);
+    }
+    gdk_cursor_unref(cursor);
 }
 
 static void on_cursor_theme_sel_changed(GtkTreeSelection* tree_sel, gpointer user_data)
@@ -85,14 +100,22 @@ static void on_cursor_theme_size_changed(GtkRange* range, gpointer user_data)
 
 void cursor_theme_init(GtkBuilder* b)
 {
+    int max_cursor_w, max_cursor_h, max_size;
     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);
 
+    gdk_display_get_maximal_cursor_size(gdk_display_get_default(), &max_cursor_w, &max_cursor_h);
+    max_size = MAX(max_cursor_w, max_cursor_h);
+
+    /* FIXME: this isn't fully working... */
     app.cursor_size_range = GTK_RANGE(gtk_builder_get_object(b, "cursor_size"));
+    if(max_size < 128)
+        gtk_range_set_range(app.cursor_size_range, 1, max_size + 10); /* 10 is page 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);
 
+    /* set up demo for cursors */
     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 4f69f4d..c2042e1 100644 (file)
@@ -32,6 +32,7 @@
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
 #include <gdk/gdkx.h>
+#include <string.h>
 
 #include "widget-theme.h"
 #include "icon-theme.h"
@@ -41,6 +42,7 @@
 LXAppearance app = {0};
 
 Atom lxsession_atom = 0;
+static const char* lxsession_name = NULL;
 
 static void check_lxsession()
 {
@@ -49,7 +51,10 @@ static void check_lxsession()
     {
         XGrabServer( GDK_DISPLAY() );
         if( XGetSelectionOwner( GDK_DISPLAY(), lxsession_atom ) )
+        {
             app.use_lxsession = TRUE;
+            lxsession_name = g_getenv("DESKTOP_SESSION");
+        }
         XUngrabServer( GDK_DISPLAY() );
     }
 }
@@ -59,14 +64,144 @@ static GOptionEntry option_entries[] =
     { NULL }
 };
 
-static void lxappearance_save_gtkrc()
+static void save_cursor_theme_name()
+{
+    char* dir_path;
+    if(!app.cursor_theme || !g_strcmp0(app.cursor_theme, "default"))
+        return;
+
+    dir_path = g_build_filename(g_get_home_dir(), ".icons/default", NULL);
+    if(0 == g_mkdir_with_parents(dir_path, 0700))
+    {
+        char* index_theme = g_build_filename(dir_path, "index.theme", NULL);
+        char* content = g_strdup_printf(
+            "# This file is written by LXAppearance. Do not edit."
+            "[Icon Theme]\n"
+            "Name=Default\n"
+            "Comment=Default Cursor Theme\n"
+            "Inherits=%s\n", app.cursor_theme);
+        g_file_set_contents(index_theme, content, -1, NULL);
+        g_free(content);
+        g_free(index_theme);
+    }
+    g_free(dir_path);
+
+    /*
+    dir_path = g_build_filename(g_get_home_dir(), ".Xdefaults", NULL);
+    Xcursor.theme: name
+    Xcursor.size: [size]
+    g_file_set_contents(dir_path, "", -1, NULL);
+    g_free(dir_path);
+    */
+}
+
+static void reload_all_programs()
 {
+    GdkEventClient event;
+    event.type = GDK_CLIENT_EVENT;
+    event.send_event = TRUE;
+    event.window = NULL;
 
+    if( app.use_lxsession )
+    {
+        event.message_type = gdk_atom_intern_static_string("_LXSESSION");
+        event.data.b[0] = 0;    /* LXS_RELOAD */
+    }
+    else
+    {
+        /* if( icon_only )
+            event.message_type = gdk_atom_intern("_GTK_LOAD_ICONTHEMES", FALSE);
+        */
+        event.message_type = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
+    }
+    event.data_format = 8;
+    gdk_event_send_clientmessage_toall((GdkEvent *)&event);
+}
+
+static void lxappearance_save_gtkrc()
+{
+    static const char* tb_styles[]={
+        "GTK_TOOLBAR_ICONS",
+        "GTK_TOOLBAR_TEXT",
+        "GTK_TOOLBAR_BOTH",
+        "GTK_TOOLBAR_BOTH_HORIZ"
+    };
+    static const char* tb_icon_sizes[]={
+        "GTK_ICON_SIZE_INVALID",
+        "GTK_ICON_SIZE_MENU",
+        "GTK_ICON_SIZE_SMALL_TOOLBAR",
+        "GTK_ICON_SIZE_LARGE_TOOLBAR",
+        "GTK_ICON_SIZE_BUTTON",
+        "GTK_ICON_SIZE_DND",
+        "GTK_ICON_SIZE_DIALOG"
+    };
+
+    char* file_path = g_build_filename(g_get_home_dir(), "~/.gtkrc-2.0", NULL);
+    char* content = g_strdup_printf(
+        "# DO NOT EDIT! This file will be overwritten by LXAppearance.\n"
+        "# Any customization should be done in ~/.gtkrc-2.0.mine instead.\n\n"
+        "gtk-theme-name=\"%s\"\n"
+        "gtk-icon-theme-name=\"%s\"\n"
+        "gtk-font-name=\"%s\"\n"
+        "gtk-toolbar-style=%s\n"
+        "gtk-toolbar-icon-size=%s\n"
+        "gtk-cursor-theme-name=\"%s\"\n"
+        "gtk-cursor-theme-size=%d\n"
+        "include \"%s/.gtkrc-2.0.mine\"\n",
+        app.widget_theme,
+        app.icon_theme,
+        app.default_font,
+        tb_styles[app.toolbar_style],
+        tb_icon_sizes[app.toolbar_icon_size],
+        app.cursor_theme,
+        app.cursor_theme_size,
+        g_get_home_dir());
+
+    g_file_set_contents(file_path, content, -1, NULL);
+    g_free(content);
+    g_free(file_path);
 }
 
 static void lxappearance_save_lxsession()
 {
+    char* rel_path = g_strconcat("lxsession/", lxsession_name, "/desktop.conf", NULL);
+    char* user_config_file = g_build_filename(g_get_user_config_dir(), rel_path, NULL);
+    char* buf;
+    int len;
+    GKeyFile* kf = g_key_file_new();
+
+    if(!g_key_file_load_from_file(kf, user_config_file, G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL))
+    {
+        /* the user config file doesn't exist, create its parent dir */
+        len = strlen(user_config_file) - strlen("/desktop.conf");
+        user_config_file[len] = '\0';
+        g_debug("user_config_file = %s", user_config_file);
+        g_mkdir_with_parents(user_config_file, 0700);
+        user_config_file[len] = '/';
+
+        g_key_file_load_from_dirs(kf, rel_path, g_get_system_config_dirs(), NULL, G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
+    }
+
+    g_free(rel_path);
 
+    g_key_file_set_string( kf, "GTK", "sNet/ThemeName", app.widget_theme );
+    g_key_file_set_string( kf, "GTK", "sGtk/FontName", app.default_font );
+
+    g_key_file_set_string( kf, "GTK", "sNet/IconThemeName", app.icon_theme );
+
+    g_key_file_set_string( kf, "GTK", "sGtk/CursorThemeName", app.cursor_theme );
+    g_key_file_set_integer( kf, "GTK", "iGtk/CursorThemeSize", app.cursor_theme_size );
+    save_cursor_theme_name();
+
+    g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarStyle", app.toolbar_style );
+    g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarIconSize", app.toolbar_icon_size );
+
+    buf = g_key_file_to_data( kf, &len, NULL );
+    g_key_file_free(kf);
+
+    g_file_set_contents(user_config_file, buf, len, NULL);
+    g_free(buf);
+    g_free(user_config_file);
 }
 
 static void on_dlg_response(GtkDialog* dlg, int res, gpointer user_data)
@@ -80,6 +215,8 @@ static void on_dlg_response(GtkDialog* dlg, int res, gpointer user_data)
         else
             lxappearance_save_gtkrc();
 
+        reload_all_programs();
+
         app.changed = FALSE;
         gtk_dialog_set_response_sensitive(app.dlg, GTK_RESPONSE_APPLY, FALSE);
         break;
@@ -105,6 +242,7 @@ static void settings_init()
     GtkSettings* settings = gtk_settings_get_default();
     g_object_get(settings,
                 "gtk-theme-name", &app.widget_theme,
+                "gtk-font-name", &app.default_font,
                 "gtk-icon-theme-name", &app.icon_theme,
                 "gtk-cursor-theme-name", &app.cursor_theme,
                 "gtk-cursor-theme-size", &app.cursor_theme_size,
index 6a8ca86..b2af84b 100644 (file)
@@ -32,6 +32,7 @@ struct _LXAppearance
 
     GtkWidget* widget_theme_view;
     GtkListStore* widget_theme_store;
+    GtkWidget* default_font_btn;
 
     GtkWidget* icon_theme_view;
     GtkListStore* icon_theme_store;
@@ -47,6 +48,7 @@ struct _LXAppearance
     GtkWidget* tb_icon_size_combo;
 
     char* widget_theme;
+    char* default_font;
     char* icon_theme;
     char* cursor_theme;
     int cursor_theme_size;
index bcc953a..6e23747 100644 (file)
@@ -113,6 +113,19 @@ static void load_themes()
     // g_signal_connect(gtk_settings_get_default(), "notify::gtk-theme-name", G_CALLBACK(on_sel_changed), NULL);
 }
 
+static void on_font_set(GtkFontButton* btn, gpointer user_data)
+{
+    const char* font_name = gtk_font_button_get_font_name(btn);
+    if(g_strcmp0(font_name, app.default_font))
+    {
+        g_free(app.default_font);
+        app.default_font = g_strdup(font_name);
+        g_object_set(gtk_settings_get_default(), "gtk-font-name", font_name, NULL);
+
+        lxappearance_changed();
+    }
+}
+
 void widget_theme_init(GtkBuilder* b)
 {
     GtkWidget* demo;
@@ -127,4 +140,8 @@ void widget_theme_init(GtkBuilder* b)
 
     /* load available themes */
     load_themes();
+
+    app.default_font_btn = GTK_WIDGET(gtk_builder_get_object(b, "default_font"));
+    gtk_font_button_set_font_name(GTK_FONT_BUTTON(app.default_font_btn), app.default_font);
+    g_signal_connect(app.default_font_btn, "font-set", G_CALLBACK(on_font_set), NULL);
 }