emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GTK3 deprecation fix (GtkFontSelection replaced with GtkFontChooser)


From: Frans Oilinki
Subject: GTK3 deprecation fix (GtkFontSelection replaced with GtkFontChooser)
Date: Fri, 10 Aug 2012 17:35:28 +0800

Hello,

I just tried building the newest emacs master branch (git cloned
repository), running Ubuntu 12.04 GNU/Linux system.

I made a mistake of adding option  "--enable-gcc-warnings" to
"./configure" (not anticipating it would add option -Werror :-). The
complete list of options to ./configure: "--prefix=/usr/local
--program-suffix=-git.master --enable-check-lisp-object-type
--enable-link-time-optimization  --enable-gcc-warnings
--with-x-toolkit=gtk3 --with-x".

The file "src/gtkutil.c" gave the following warning:

    gcc -std=gnu99 -c  -Demacs  -I.
-I/home/fo/work/OpenSource/Emacs/emacs/src -I../lib
-I/home/fo/work/OpenSource/Emacs/emacs/src/../lib   -pthread -isystem
/usr/include/gtk-3.0 -isystem /usr/include/pango-1.0 -isystem
/usr/include/gio-unix-2.0/ -isystem /usr/include/atk-1.0 -isystem
/usr/include/cairo -isystem /usr/include/gdk-pixbuf-2.0 -isystem
/usr/include/freetype2 -isystem /usr/include/glib-2.0 -isystem
/usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem
/usr/include/pixman-1 -isystem /usr/include/libpng12   -isystem
/usr/include/freetype2    -isystem /usr/include/alsa   -pthread
-isystem /usr/include/librsvg-2.0 -isystem /usr/include/glib-2.0
-isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem
/usr/include/gdk-pixbuf-2.0 -isystem /usr/include/cairo -isystem
/usr/include/libpng12 -isystem /usr/include/pixman-1 -isystem
/usr/include/freetype2   -fopenmp -isystem /usr/include/ImageMagick
-isystem /usr/include/libxml2   -isystem /usr/include/dbus-1.0
-isystem /usr/lib/x86_64-linux-gnu/dbus-1.0/include   -pthread
-isystem /usr/include/glib-2.0 -isystem
/usr/lib/x86_64-linux-gnu/glib-2.0/include   -pthread -isystem
/usr/include/gconf/2 -isystem /usr/include/dbus-1.0 -isystem
/usr/lib/x86_64-linux-gnu/dbus-1.0/include -isystem
/usr/include/glib-2.0 -isystem
/usr/lib/x86_64-linux-gnu/glib-2.0/include   -isystem
/usr/include/freetype2    -isystem /usr/include/freetype2    -MMD -MF
deps/gtkutil.d -MP  -isystem /usr/include/p11-kit-1   -Wall -W
-Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs
-Wunused -Wunknown-pragmas -Wstrict-aliasing
-Wdeclaration-after-statement -Wpointer-arith -Wbad-function-cast
-Wcast-align -Wwrite-strings -Wstrict-prototypes
-Wold-style-definition -Wmissing-prototypes -Wmissing-declarations
-Wmissing-noreturn -Wmissing-format-attribute -Wpacked -Winvalid-pch
-Wvolatile-register-var -Wdisabled-optimization
-Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat
-Wattributes -Wcoverage-mismatch -Wunused-macros -Wabi -Wcpp
-Wdeprecated -Wdeprecated-declarations -Wdiv-by-zero
-Wdouble-promotion -Wendif-labels -Wextra -Wformat-contains-nul
-Wformat-extra-args -Wformat-zero-length -Wformat=2 -Wmultichar
-Wnormalized=nfc -Woverflow -Wpointer-to-int-cast -Wpragmas
-Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wtrampolines
-Wno-missing-field-initializers -Wno-missing-field-initializers
-Wno-sign-compare -Wno-type-limits -Wno-switch -Wno-unused-parameter
-Wno-format-nonliteral -Wno-logical-op -fdiagnostics-show-option
-funit-at-a-time -Werror -g -O2 -flto=1 gtkutil.c
    gtkutil.c: In function ‘xg_get_font_name’:
    gtkutil.c:2003:3: error: ‘gtk_font_selection_dialog_new’ is
deprecated (declared at
/usr/include/gtk-3.0/gtk/deprecated/gtkfontsel.h:142): Use
'GtkFontChooser' instead [-Werror=deprecated-declarations]
    gtkutil.c:2006:3: error: ‘gtk_font_selection_dialog_set_font_name’
is deprecated (declared at
/usr/include/gtk-3.0/gtk/deprecated/gtkfontsel.h:153): Use
'GtkFontChooser' instead [-Werror=deprecated-declarations]
    gtkutil.c:2019:7: error: ‘gtk_font_selection_dialog_get_font_name’
is deprecated (declared at
/usr/include/gtk-3.0/gtk/deprecated/gtkfontsel.h:151): Use
'GtkFontChooser' instead [-Werror=deprecated-declarations]
    cc1: all warnings being treated as errors
    make[1]: *** [gtkutil.o] Error 1
    make[1]: *** Waiting for unfinished jobs....
    make[1]: Leaving directory `/home/fo/work/OpenSource/Emacs/emacs/src'
    make: *** [src] Error 2

I found GTK3 API documentation and within couple of minutes of reading
quickly applied the following fix:

    $ git diff
     diff --git a/src/gtkutil.c b/src/gtkutil.c
     index 4879479..ce9b851 100644
     --- a/src/gtkutil.c
     +++ b/src/gtkutil.c
     @@ -2000,11 +2000,10 @@ xg_get_font_name (FRAME_PTR f, const char
*default_name)
        sigblock (sigmask (__SIGRTMIN));
      #endif /* HAVE_PTHREAD */

     -  w = gtk_font_selection_dialog_new ("Pick a font");
     +  w = gtk_font_chooser_dialog_new ("Pick a font", NULL);
        if (!default_name)
          default_name = "Monospace 10";
     -  gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (w),
     -                                           default_name);
     +  gtk_font_chooser_set_font (GTK_FONT_CHOOSER (w), default_name);

        gtk_widget_set_name (w, "emacs-fontdialog");

     @@ -2015,8 +2014,7 @@ xg_get_font_name (FRAME_PTR f, const char
*default_name)
      #endif

        if (done == GTK_RESPONSE_OK)
     -    fontname = gtk_font_selection_dialog_get_font_name
     -      (GTK_FONT_SELECTION_DIALOG (w));
     +    fontname = gtk_font_chooser_get_font(GTK_FONT_CHOOSER (w));

        gtk_widget_destroy (w);
        return fontname;

This fixed the compilation for my Ubuntu 12.04 machine (gtk3 seems to
be version 3.4.2). I tried selecting font (by [SHIFT] +
[LEFT-MOUSE-BUTTON]), and the new font selection widget worked for me.

Note that I have never before done programming with GTK API, so you
might review this with some care, and check the compatibility with the
supported versions of GTK3 if you choose to apply this kind of fix to
future versions of Emacs.

Best regards and thanks for everybody's work for fabulous text editing
environment (or whatever emacs should be called),

Frans



reply via email to

[Prev in Thread] Current Thread [Next in Thread]