Merging upstream version 0.5.1.
[debian/lxappearance.git] / src / lxappearance.c
index d6824da..43b6d76 100644 (file)
@@ -38,6 +38,7 @@
 #include "color-scheme.h"
 #include "icon-theme.h"
 #include "cursor-theme.h"
+#include "font.h"
 #include "other.h"
 #include "plugin.h"
 
@@ -48,16 +49,16 @@ static const char* lxsession_name = NULL;
 
 static void check_lxsession()
 {
-    lxsession_atom = XInternAtom( GDK_DISPLAY(), "_LXSESSION", True );
+    lxsession_atom = XInternAtom( GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "_LXSESSION", True );
     if( lxsession_atom != None )
     {
-        XGrabServer( GDK_DISPLAY() );
-        if( XGetSelectionOwner( GDK_DISPLAY(), lxsession_atom ) )
+        XGrabServer( GDK_DISPLAY_XDISPLAY(gdk_display_get_default()) );
+        if( XGetSelectionOwner( GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), lxsession_atom ) )
         {
             app.use_lxsession = TRUE;
             lxsession_name = g_getenv("DESKTOP_SESSION");
         }
-        XUngrabServer( GDK_DISPLAY() );
+        XUngrabServer( GDK_DISPLAY_XDISPLAY(gdk_display_get_default()) );
     }
 }
 
@@ -99,6 +100,11 @@ static void save_cursor_theme_name()
 
 static void reload_all_programs()
 {
+#if GTK_CHECK_VERSION(3, 0, 0)
+
+/* TODO Port this to something else than gdk_event_send_clientmessage_toall */
+
+#else
     GdkEventClient event;
     event.type = GDK_CLIENT_EVENT;
     event.send_event = TRUE;
@@ -118,6 +124,7 @@ static void reload_all_programs()
     }
     event.data_format = 8;
     gdk_event_send_clientmessage_toall((GdkEvent *)&event);
+#endif
 }
 
 static const char* bool2str(gboolean val)
@@ -125,6 +132,7 @@ static const char* bool2str(gboolean val)
     return val ? "TRUE" : "FALSE";
 }
 
+
 static void lxappearance_save_gtkrc()
 {
     static const char* tb_styles[]={
@@ -172,6 +180,9 @@ static void lxappearance_save_gtkrc()
         "gtk-enable-event-sounds=%d\n"
         "gtk-enable-input-feedback-sounds=%d\n"
 #endif
+        "gtk-xft-antialias=%d\n"
+        "gtk-xft-hinting=%d\n"
+
         , app.cursor_theme_size,
         tb_styles[app.toolbar_style],
         tb_icon_sizes[app.toolbar_icon_size],
@@ -179,15 +190,25 @@ static void lxappearance_save_gtkrc()
         app.menu_images ? 1 : 0,
 #if GTK_CHECK_VERSION(2, 14, 0)
         app.enable_event_sound ? 1 : 0,
-        app.enable_input_feedback ? 1 : 0
+        app.enable_input_feedback ? 1 : 0,
 #endif
+        app.enable_antialising ? 1 : 0,
+        app.enable_hinting ? 1 : 0
         );
 
+    if(app.hinting_style)
+        g_string_append_printf(content,
+            "gtk-xft-hintstyle=\"%s\"\n", app.hinting_style);
+
+    if(app.font_rgba)
+        g_string_append_printf(content,
+            "gtk-xft-rgba=\"%s\"\n", app.font_rgba);
+
     if(app.color_scheme)
     {
         char* escaped = g_strescape(app.color_scheme, NULL);
         g_string_append_printf(content,
-            "gtk-color-scheme=\"\"\n",
+            "gtk-color-scheme=\"%s\"\n",
             escaped);
         g_free(escaped);
     }
@@ -197,6 +218,19 @@ static void lxappearance_save_gtkrc()
         g_get_home_dir());
 
     g_file_set_contents(file_path, content->str, content->len, NULL);
+
+    /* Save also for GTK3 */
+    g_string_prepend(content, "[Settings] \n");
+    char* file_path_gtk3 = g_build_filename(g_get_home_dir(), "gtk-3.0", NULL);
+    char* file_path_settings = g_build_filename(g_get_home_dir(), "gtk-3.0", "settings.ini", NULL);
+
+    if (!g_file_test(file_path_gtk3, G_FILE_TEST_IS_DIR))
+    {
+        g_mkdir_with_parents(file_path_gtk3, 0755);
+    }
+
+    g_file_set_contents(file_path_settings, content->str, content->len, NULL);
+
     g_string_free(content, TRUE);
     g_free(file_path);
 }
@@ -249,6 +283,10 @@ static void lxappearance_save_lxsession()
     g_key_file_set_integer( kf, "GTK", "iNet/EnableEventSounds", app.enable_event_sound);
     g_key_file_set_integer( kf, "GTK", "iNet/EnableInputFeedbackSounds", app.enable_input_feedback);
 #endif
+    g_key_file_set_integer( kf, "GTK", "iXft/Antialias", app.enable_antialising);
+    g_key_file_set_integer( kf, "GTK", "iXft/Hinting", app.enable_hinting);
+    g_key_file_set_string( kf, "GTK", "sXft/HintStyle", app.hinting_style);
+    g_key_file_set_string( kf, "GTK", "sXft/RGBA", app.font_rgba);
 
     buf = g_key_file_to_data( kf, &len, NULL );
     g_key_file_free(kf);
@@ -308,6 +346,10 @@ static void settings_init()
                 "gtk-enable-event-sounds", &app.enable_event_sound,
                 "gtk-enable-input-feedback-sounds", &app.enable_input_feedback,
 #endif
+                "gtk-xft-antialias", &app.enable_antialising,
+                "gtk-xft-hinting", &app.enable_hinting,
+                "gtk-xft-hintstyle", &app.hinting_style,
+                "gtk-xft-rgba", &app.font_rgba,
                 NULL);
     /* try to figure out cursor theme used. */
     if(!app.cursor_theme || g_strcmp0(app.cursor_theme, "default") == 0)
@@ -411,6 +453,7 @@ int main(int argc, char** argv)
     color_scheme_init(b);
     icon_theme_init(b);
     cursor_theme_init(b);
+    font_init(b);
     other_init(b);
     /* the page for window manager plugins */
     app.wm_page = GTK_WIDGET(gtk_builder_get_object(b, "wm_page"));
@@ -437,3 +480,14 @@ void lxappearance_changed()
         gtk_dialog_set_response_sensitive(GTK_DIALOG(app.dlg), GTK_RESPONSE_APPLY, TRUE);
     }
 }
+
+void on_check_button_toggled(GtkToggleButton* btn, gpointer user_data)
+{
+    gboolean* val = (gboolean*)user_data;
+    gboolean new_val = gtk_toggle_button_get_active(btn);
+    if(new_val != *val)
+    {
+        *val = new_val;
+        lxappearance_changed();
+    }
+}