]> code.delx.au - gnu-emacs/blobdiff - src/xsettings.c
* lisp/emacs-lisp/syntax.el (syntax-ppss-toplevel-pos): Fix typo in docstring.
[gnu-emacs] / src / xsettings.c
index 9c4749f4036a9fd1037efa1527210558bc7f546e..945007db2f06229fd24d2e379f173c5fd36f9a3e 100644 (file)
@@ -1,5 +1,5 @@
 /* Functions for handle font changes dynamically.
-   Copyright (C) 2009
+   Copyright (C) 2009, 2010
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -24,6 +24,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "xterm.h"
 #include "xsettings.h"
 #include "frame.h"
+#include "keyboard.h"
 #include "blockinput.h"
 #include "termhooks.h"
 #include "termopts.h"
@@ -41,6 +42,8 @@ static char *current_mono_font;
 static struct x_display_info *first_dpyinfo;
 static Lisp_Object Qfont_name, Qfont_render;
 static int use_system_font;
+static Lisp_Object Vxft_settings;
+
 
 #ifdef HAVE_GCONF
 static GConfClient *gconf_client;
@@ -137,11 +140,21 @@ get_prop_window (dpyinfo)
   XUngrabServer (dpy);
 }
 
+enum {
+  SEEN_AA         = 0x01,
+  SEEN_HINTING    = 0x02,
+  SEEN_RGBA       = 0x04,
+  SEEN_LCDFILTER  = 0x08,
+  SEEN_HINTSTYLE  = 0x10,
+  SEEN_DPI        = 0x20,
+};
 struct xsettings 
 {
   FcBool aa, hinting;
   int rgba, lcdfilter, hintstyle;
   double dpi;
+
+  unsigned seen;
 };
 
 #define SWAP32(nr) (((nr) << 24) | (((nr) << 8) & 0xff0000)     \
@@ -196,6 +209,7 @@ struct xsettings
    2      CARD16        green
    2      CARD16        alpha
 
+   Returns non-zero if some Xft settings was seen, zero otherwise.
 */
 
 static int
@@ -293,11 +307,18 @@ parse_xft_settings (prop, bytes, settings)
         {
           ++settings_seen;
           if (strcmp (name, "Xft/Antialias") == 0)
-            settings->aa = ival != 0;
+            {
+              settings->seen |= SEEN_AA;
+              settings->aa = ival != 0;
+            }
           else if (strcmp (name, "Xft/Hinting") == 0)
-            settings->hinting = ival != 0;
+            {
+              settings->seen |= SEEN_HINTING;
+              settings->hinting = ival != 0;
+            }
           else if (strcmp (name, "Xft/HintStyle") == 0)
             {
+              settings->seen |= SEEN_HINTSTYLE;
               if (strcmp (sval, "hintnone") == 0)
                 settings->hintstyle = FC_HINT_NONE;
               else if (strcmp (sval, "hintslight") == 0)
@@ -306,9 +327,12 @@ parse_xft_settings (prop, bytes, settings)
                 settings->hintstyle = FC_HINT_MEDIUM;
               else if (strcmp (sval, "hintfull") == 0)
                 settings->hintstyle = FC_HINT_FULL;
+              else
+                settings->seen &= ~SEEN_HINTSTYLE;
             }
           else if (strcmp (name, "Xft/RGBA") == 0)
             {
+              settings->seen |= SEEN_RGBA;
               if (strcmp (sval, "none") == 0)
                 settings->rgba = FC_RGBA_NONE;
               else if (strcmp (sval, "rgb") == 0)
@@ -319,20 +343,28 @@ parse_xft_settings (prop, bytes, settings)
                 settings->rgba = FC_RGBA_VRGB;
               else if (strcmp (sval, "vbgr") == 0)
                 settings->rgba = FC_RGBA_VBGR;
+              else
+                settings->seen &= ~SEEN_RGBA;
             }
           else if (strcmp (name, "Xft/DPI") == 0)
-            settings->dpi = (double)ival/1024.0;
+            {
+              settings->seen |= SEEN_DPI;
+              settings->dpi = (double)ival/1024.0;
+            }
           else if (strcmp (name, "Xft/lcdfilter") == 0)
             {
+              settings->seen |= SEEN_LCDFILTER;
               if (strcmp (sval, "none") == 0)
                 settings->lcdfilter = FC_LCD_NONE;
               else if (strcmp (sval, "lcddefault") == 0)
                 settings->lcdfilter = FC_LCD_DEFAULT;
+              else
+                settings->seen &= ~SEEN_LCDFILTER;
             }
         }
     }
 
-  return Success;
+  return settings_seen;
 }
 
 static int
@@ -364,7 +396,7 @@ read_xft_settings (dpyinfo, settings)
 
   x_uncatch_errors ();
 
-  return rc == Success;
+  return rc != 0;
 }
 
 
@@ -376,12 +408,13 @@ apply_xft_settings (dpyinfo, send_event_p)
   FcPattern *pat;
   struct xsettings settings, oldsettings;
   int changed = 0;
+  char buf[256];
 
   if (!read_xft_settings (dpyinfo, &settings))
     return;
 
   memset (&oldsettings, 0, sizeof (oldsettings));
-
+  buf[0] = '\0';
   pat = FcPatternCreate ();
   XftDefaultSubstitute (dpyinfo->display,
                         XScreenNumberOfScreen (dpyinfo->screen),
@@ -393,45 +426,68 @@ apply_xft_settings (dpyinfo, send_event_p)
   FcPatternGetInteger (pat, FC_RGBA, 0, &oldsettings.rgba);
   FcPatternGetDouble (pat, FC_DPI, 0, &oldsettings.dpi);
 
-  if (oldsettings.aa != settings.aa)
+  if ((settings.seen & SEEN_AA) != 0 && oldsettings.aa != settings.aa)
     {
       FcPatternDel (pat, FC_ANTIALIAS);
       FcPatternAddBool (pat, FC_ANTIALIAS, settings.aa);
       ++changed;
+      oldsettings.aa = settings.aa;
     }
-  if (oldsettings.hinting != settings.hinting)
+  sprintf (buf, "Antialias: %d", oldsettings.aa);
+
+  if ((settings.seen & SEEN_HINTING) != 0
+      && oldsettings.hinting != settings.hinting)
     {
       FcPatternDel (pat, FC_HINTING);
       FcPatternAddBool (pat, FC_HINTING, settings.hinting);
       ++changed;
+      oldsettings.hinting = settings.hinting;
     }
-  if (oldsettings.rgba != settings.rgba)
+  if (strlen (buf) > 0) strcat (buf, ", ");
+  sprintf (buf+strlen (buf), "Hinting: %d", oldsettings.hinting);
+  if ((settings.seen & SEEN_RGBA) != 0 && oldsettings.rgba != settings.rgba)
     {
       FcPatternDel (pat, FC_RGBA);
       FcPatternAddInteger (pat, FC_RGBA, settings.rgba);
+      oldsettings.rgba = settings.rgba;
       ++changed;
     }
+  if (strlen (buf) > 0) strcat (buf, ", ");
+  sprintf (buf+strlen (buf), "RGBA: %d", oldsettings.rgba);
+
   /* Older fontconfig versions don't have FC_LCD_FILTER. */
-  if (oldsettings.lcdfilter != settings.lcdfilter)
+  if ((settings.seen & SEEN_LCDFILTER) != 0
+      && oldsettings.lcdfilter != settings.lcdfilter)
     {
       FcPatternDel (pat, FC_LCD_FILTER);
       FcPatternAddInteger (pat, FC_LCD_FILTER, settings.lcdfilter);
       ++changed;
+      oldsettings.lcdfilter = settings.lcdfilter;
     }
-  if (oldsettings.hintstyle != settings.hintstyle)
+  if (strlen (buf) > 0) strcat (buf, ", ");
+  sprintf (buf+strlen (buf), "LCDFilter: %d", oldsettings.lcdfilter);
+
+  if ((settings.seen & SEEN_HINTSTYLE) != 0
+      && oldsettings.hintstyle != settings.hintstyle)
     {
       FcPatternDel (pat, FC_HINT_STYLE);
       FcPatternAddInteger (pat, FC_HINT_STYLE, settings.hintstyle);
       ++changed;
+      oldsettings.hintstyle = settings.hintstyle;
     }
-  if (oldsettings.dpi != settings.dpi)
+  if (strlen (buf) > 0) strcat (buf, ", ");
+  sprintf (buf+strlen (buf), "Hintstyle: %d", oldsettings.hintstyle);
+
+  if ((settings.seen & SEEN_DPI) != 0 && oldsettings.dpi != settings.dpi
+      && settings.dpi > 0)
     {
       Lisp_Object frame, tail;
 
       FcPatternDel (pat, FC_DPI);
       FcPatternAddDouble (pat, FC_DPI, settings.dpi);
       ++changed;
-
+      oldsettings.dpi = settings.dpi;
+      
       /* Change the DPI on this display and all frames on the display.  */
       dpyinfo->resy = dpyinfo->resx = settings.dpi;
       FOR_EACH_FRAME (tail, frame)
@@ -440,12 +496,16 @@ apply_xft_settings (dpyinfo, send_event_p)
           XFRAME (frame)->resy = XFRAME (frame)->resx = settings.dpi;
     }
 
+  if (strlen (buf) > 0) strcat (buf, ", ");
+  sprintf (buf+strlen (buf), "DPI: %lf", oldsettings.dpi);
+
   if (changed)
     {
       XftDefaultSet (dpyinfo->display, pat);
       if (send_event_p)
         store_font_changed_event (Qfont_render,
                                   XCAR (dpyinfo->name_list_element));
+      Vxft_settings = make_string (buf, strlen (buf));
     }
   else
     FcPatternDestroy (pat);
@@ -604,6 +664,10 @@ syms_of_xsettings ()
     doc: /* *Non-nil means to use the system defined font.  */);
   use_system_font = 0;
 
+  DEFVAR_LISP ("xft-settings", &Vxft_settings,
+               doc: /* Font settings applied to Xft.  */);
+  Vxft_settings = make_string ("", 0);
+
 #ifdef HAVE_XFT
   Fprovide (intern_c_string ("font-render-setting"), Qnil);
 #ifdef HAVE_GCONF