Mac OS X gtk-quartz backend support
Brought to you by:
andreasb123,
auroux
Hi,
In order to get xournal compiling against the gtk-quartz backend I had to make the following changes to the code. Please consider them for future updates:
diff --git a/src/Makefile.am b/src/Makefile.am
index 9f9f1a2..6b18256 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,6 +31,6 @@ if WIN32
xournal_LDFLAGS = -mwindows
xournal_LDADD = win32/xournal.res ttsubset/libttsubset.a @PACKAGE_LIBS@ $(INTLLIBS) -lz
else
- xournal_LDADD = ttsubset/libttsubset.a @PACKAGE_LIBS@ $(INTLLIBS) -lX11 -lz -lm
+ xournal_LDADD = ttsubset/libttsubset.a @PACKAGE_LIBS@ $(INTLLIBS) -lz -lm
endif
diff --git a/src/xo-file.c b/src/xo-file.c
index a1c19c9..cc38d14 100644
--- a/src/xo-file.c
+++ b/src/xo-file.c
@@ -31,10 +31,6 @@
#include <glib/gstdio.h>
#include <poppler/glib/poppler.h>
-#ifndef WIN32
- #include <gdk/gdkx.h>
- #include <X11/Xlib.h>
-#endif
#include "xournal.h"
#include "xo-interface.h"
@@ -1275,50 +1271,8 @@ GList *attempt_load_gv_bg(char *filename)
struct Background *attempt_screenshot_bg(void)
{
-#ifndef WIN32
- struct Background *bg;
- GdkPixbuf *pix;
- XEvent x_event;
- GdkWindow *window;
- GdkColormap *cmap;
- int x,y,w,h;
- Window x_root, x_win;
-
- x_root = gdk_x11_get_default_root_xwindow();
-
- if (!XGrabButton(GDK_DISPLAY(), AnyButton, AnyModifier, x_root,
- False, ButtonReleaseMask, GrabModeAsync, GrabModeSync, None, None))
- return NULL;
-
- XWindowEvent (GDK_DISPLAY(), x_root, ButtonReleaseMask, &x_event);
- XUngrabButton(GDK_DISPLAY(), AnyButton, AnyModifier, x_root);
-
- x_win = x_event.xbutton.subwindow;
- if (x_win == None) x_win = x_root;
-
- window = gdk_window_foreign_new_for_display(gdk_display_get_default(), x_win);
-
- gdk_window_get_geometry(window, &x, &y, &w, &h, NULL);
- cmap = gdk_drawable_get_colormap(window);
- if (cmap == NULL) cmap = gdk_colormap_get_system();
-
- pix = gdk_pixbuf_get_from_drawable(NULL, window,
- cmap, 0, 0, 0, 0, w, h);
-
- if (pix == NULL) return NULL;
-
- bg = g_new(struct Background, 1);
- bg->type = BG_PIXMAP;
- bg->canvas_item = NULL;
- bg->pixbuf = pix;
- bg->pixbuf_scale = DEFAULT_ZOOM;
- bg->filename = new_refstring(NULL);
- bg->file_domain = DOMAIN_ATTACH;
- return bg;
-#else
// not implemented under WIN32
return FALSE;
-#endif
}
/************** pdf annotation ***************/
diff --git a/src/xo-misc.c b/src/xo-misc.c
index 2af7f43..f9003bd 100644
--- a/src/xo-misc.c
+++ b/src/xo-misc.c
@@ -2288,9 +2288,7 @@ void hide_unimplemented(void)
}
/* screenshot feature doesn't work yet in Win32 */
-#ifdef WIN32
gtk_widget_hide(GET_COMPONENT("journalScreenshot"));
-#endif
}
// toggle fullscreen mode
Hi there,
On 06/15/2015 03:08 AM, Tom Schoonjans wrote:> In order to get xournal
compiling against the gtk-quartz backend I had
Thanks for the report. We can't make these changes as listed, because
they break support for X11 backends (including linux) -- instead, one
should add another set of conditionals for MacOS X (just like the WIN32
conditionals for the Windows environment).
Ideally, we would auto-detect this. Does anyone competent with
autoconf know how to tweak configure.in to either detect the presence of
X11 and set a variable X11, or else detect the presence of MacOS with no
X11 and set a variable QUARTZ, or at least allow a user configuration
option (as in "configure --no-X11" or something like that to disable
X11-specific code) ?
(Question: on MacOS with X11 available, is it better to use X11 or to
use Quartz? hmm, presumably what matters is how GTK is compiled...)
Thanks,
Denis
Hi,
I know the code I provided was more of a hack than really a patch :-)
This is because Homebrew is in the process of transitioning to gtk2 with quartz backend only. We have just had too many problems supporting both X11 and quartz versions.
IMHO, gtk+2 should always be built on Mac OS X with quartz backend: it just looks better (especially on retina screens which the X11 backend doesn’t properly support) and integrates really nicely into the user interface, in particular when you use gtk-mac-integration too.
In your case, you will have to make a couple of changes:
in src/Makefile.am: remove the explicit -lX11 linking. It’s pointless as gtk+ will pull it in anyway if its compiled with X11 backend support (Linux and Mac OS X).
in src/xo-file.c and src/xo-misc.c: clearly the X11 dependent part has to be removed here. Instead of letting configure.in figure out which backend is being used, it is better to get the backend explicitly from the gdk headers. Including gdk/gdk.h pulls in gdkconfig.h which has the supported backend defined using macros like GDK_WINDOWING_X11, GDK_WINDOWING_QUARTZ, GDK_WINDOWING_WIN32 etc… Use these for your ifdefs blocks and you should be well on your way.
If you implement a solution like this there will never be a need to add an —with-x or —without-x option to configure: you are restricted to whatever backend gtk was compiled for anyway and the code takes care of the rest.
Best,
Tom
Related
Bugs:
#156Release 0.4.8.2016 is up to date with cvs/git repositories, and should include a fix for this bug. Please reopen if problems persist with 0.4.8.2016 or with the current cvs/git code.