Skip to content

Commit

Permalink
Merge pull request #419 from techee/osx-integration
Browse files Browse the repository at this point in the history
OS X integration
  • Loading branch information
b4n committed Mar 4, 2015
2 parents b032f2e + 7fa8b3a commit 05e19be
Show file tree
Hide file tree
Showing 15 changed files with 380 additions and 167 deletions.
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -105,6 +105,7 @@ GEANY_CHECK_MINGW

GEANY_CHECK_SOCKET
GEANY_CHECK_VTE
GEANY_CHECK_MAC_INTEGRATION
GEANY_CHECK_THE_FORCE dnl hehe

# i18n
Expand Down
18 changes: 18 additions & 0 deletions m4/geany-mac-integration.m4
@@ -0,0 +1,18 @@
dnl GEANY_CHECK_MAC_INTEGRATION
dnl Check for gtk-mac-integration to enable improved OS X integration
dnl
AC_DEFUN([GEANY_CHECK_MAC_INTEGRATION],
[
AC_ARG_ENABLE([mac-integration],
[AS_HELP_STRING([--enable-mac-integration],
[use gtk-mac-integration to enable improved OS X integration [default=no]])],
[geany_enable_mac_integration="$enableval"],
[geany_enable_mac_integration="no"])
AS_IF([test "x$geany_enable_mac_integration" = "xyes"],
[
AS_IF([test "x$enable_gtk3" = xyes],
[PKG_CHECK_MODULES(MAC_INTEGRATION, gtk-mac-integration-gtk3)],
[PKG_CHECK_MODULES(MAC_INTEGRATION, gtk-mac-integration-gtk2)])
])
])
7 changes: 4 additions & 3 deletions scintilla/gtk/ScintillaGTK.cxx
Expand Up @@ -1988,10 +1988,11 @@ gint ScintillaGTK::ScrollEvent(GtkWidget *widget, GdkEventScroll *event) {
// Compute amount and direction to scroll (even tho on win32 there is
// intensity of scrolling info in the native message, gtk doesn't
// support this so we simulate similarly adaptive scrolling)
// Note that this is disabled on OS X (Darwin) where the X11 server already has
// and adaptive scrolling algorithm that fights with this one
// Note that this is disabled on OS X (Darwin) with the X11 backend
// where the X11 server already has an adaptive scrolling algorithm
// that fights with this one
int cLineScroll;
#if defined(__MWERKS__) || defined(__APPLE_CPP__) || defined(__APPLE_CC__)
#if defined(__APPLE__) && !defined(GDK_WINDOWING_QUARTZ)
cLineScroll = sciThis->linesPerScroll;
if (cLineScroll == 0)
cLineScroll = 4;
Expand Down
4 changes: 3 additions & 1 deletion src/Makefile.am
Expand Up @@ -38,6 +38,7 @@ SRCS = \
msgwindow.c msgwindow.h \
navqueue.c navqueue.h \
notebook.c notebook.h \
osx.c osx.h \
plugins.c plugins.h \
pluginutils.c pluginutils.h \
prefix.c prefix.h \
Expand Down Expand Up @@ -89,7 +90,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/scintilla/include \
-I$(top_srcdir)/tagmanager/src \
@GTK_CFLAGS@ @GTHREAD_CFLAGS@
@GTK_CFLAGS@ @GTHREAD_CFLAGS@ $(MAC_INTEGRATION_CFLAGS)

# tell automake we have a C++ file so it uses the C++ linker we need for Scintilla
nodist_EXTRA_geany_SOURCES = dummy.cxx
Expand Down Expand Up @@ -142,6 +143,7 @@ geany_LDADD = \
$(top_builddir)/tagmanager/src/libtagmanager.a \
@GTK_LIBS@ \
@GTHREAD_LIBS@ \
$(MAC_INTEGRATION_LIBS) \
$(INTLLIBS)

AM_CFLAGS = -DGEANY_DATADIR=\""$(datadir)"\" \
Expand Down
28 changes: 1 addition & 27 deletions src/keybindings.c
Expand Up @@ -1101,23 +1101,6 @@ static gboolean check_menu_key(GeanyDocument *doc, guint keyval, guint state, gu


#ifdef HAVE_VTE
static gboolean on_menu_expose_event(GtkWidget *widget, GdkEventExpose *event,
gpointer user_data)
{
if (!gtk_widget_get_sensitive(widget))
gtk_widget_set_sensitive(GTK_WIDGET(widget), TRUE);
return FALSE;
}


#if GTK_CHECK_VERSION(3, 0, 0)
static gboolean on_menu_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
{
return on_menu_expose_event(widget, NULL, user_data);
}
#endif


static gboolean set_sensitive(gpointer widget)
{
gtk_widget_set_sensitive(GTK_WIDGET(widget), TRUE);
Expand Down Expand Up @@ -1158,16 +1141,7 @@ static gboolean check_vte(GdkModifierType state, guint keyval)
* Note: maybe there's a better way of doing this ;-) */
widget = ui_lookup_widget(main_widgets.window, "menubar1");
gtk_widget_set_sensitive(widget, FALSE);
{
/* make the menubar sensitive before it is redrawn */
static gboolean connected = FALSE;
if (!connected)
#if GTK_CHECK_VERSION(3, 0, 0)
g_signal_connect(widget, "draw", G_CALLBACK(on_menu_draw), NULL);
#else
g_signal_connect(widget, "expose-event", G_CALLBACK(on_menu_expose_event), NULL);
#endif
}
g_idle_add_full(G_PRIORITY_HIGH, set_sensitive, widget, NULL);

widget = main_widgets.editor_menu;
gtk_widget_set_sensitive(widget, FALSE);
Expand Down
67 changes: 20 additions & 47 deletions src/main.c
Expand Up @@ -62,6 +62,7 @@
#include "utils.h"
#include "vte.h"
#include "win32.h"
#include "osx.h"

#include "gtkcompat.h"

Expand Down Expand Up @@ -224,16 +225,7 @@ static void apply_settings(void)
static void main_init(void)
{
/* add our icon path in case we aren't installed in the system prefix */
gchar *path;
#ifdef G_OS_WIN32
gchar *install_dir = win32_get_installation_dir();
path = g_build_filename(install_dir, "share", "icons", NULL);
g_free(install_dir);
#else
path = g_build_filename(GEANY_DATADIR, "icons", NULL);
#endif
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), path);
g_free(path);
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), utils_resource_dir(RESOURCE_DIR_ICON));

/* inits */
ui_init_stock_items();
Expand Down Expand Up @@ -274,6 +266,9 @@ static void main_init(void)

ui_widgets.toolbar_menu = create_toolbar_popup_menu1();
ui_init();
#ifdef MAC_INTEGRATION
osx_ui_init();
#endif

/* set widget names for matching with .gtkrc-2.0 */
gtk_widget_set_name(main_widgets.window, "GeanyMainWindow");
Expand Down Expand Up @@ -400,30 +395,9 @@ static void change_working_directory_on_windows(void)

static void setup_paths(void)
{
gchar *data_dir;
gchar *doc_dir;

/* set paths */
#ifdef G_OS_WIN32
/* use the installation directory(the one where geany.exe is located) as the base for the
* documentation and data files */
gchar *install_dir = win32_get_installation_dir();

data_dir = g_build_filename(install_dir, "data", NULL); /* e.g. C:\Program Files\geany\data */
doc_dir = g_build_filename(install_dir, "doc", NULL);

g_free(install_dir);
#else
data_dir = g_build_filename(GEANY_DATADIR, "geany", NULL); /* e.g. /usr/share/geany */
doc_dir = g_build_filename(GEANY_DOCDIR, "html", NULL);
#endif

/* convert path names to locale encoding */
app->datadir = utils_get_locale_from_utf8(data_dir);
app->docdir = utils_get_locale_from_utf8(doc_dir);

g_free(data_dir);
g_free(doc_dir);
app->datadir = utils_get_locale_from_utf8(utils_resource_dir(RESOURCE_DIR_DATA));
app->docdir = utils_get_locale_from_utf8(utils_resource_dir(RESOURCE_DIR_DOC));
}


Expand Down Expand Up @@ -473,26 +447,15 @@ gboolean main_is_realized(void)
**/
void main_locale_init(const gchar *locale_dir, const gchar *package)
{
gchar *l_locale_dir = NULL;

#ifdef HAVE_LOCALE_H
setlocale(LC_ALL, "");
#endif

#ifdef G_OS_WIN32
{
gchar *install_dir = win32_get_installation_dir();
/* e.g. C:\Program Files\geany\lib\locale */
l_locale_dir = g_build_filename(install_dir, "share", "locale", NULL);
g_free(install_dir);
}
#else
l_locale_dir = g_strdup(locale_dir);
locale_dir = utils_resource_dir(RESOURCE_DIR_LOCALE);
#endif

(void) bindtextdomain(package, l_locale_dir);
(void) bindtextdomain(package, locale_dir);
(void) bind_textdomain_codeset(package, "UTF-8");
g_free(l_locale_dir);
}


Expand Down Expand Up @@ -647,6 +610,11 @@ static void parse_command_line_options(gint *argc, gchar ***argv)
g_printerr("Geany: cannot open display\n");
exit(1);
}

#ifdef MAC_INTEGRATION
/* Create GtkosxApplication singleton - should be created shortly after gtk_init() */
gtkosx_application_get();
#endif
}


Expand Down Expand Up @@ -1059,7 +1027,7 @@ gint main(gint argc, gchar **argv)
setup_gtk2_styles();
#endif
#ifdef ENABLE_NLS
main_locale_init(GEANY_LOCALEDIR, GETTEXT_PACKAGE);
main_locale_init(utils_resource_dir(RESOURCE_DIR_LOCALE), GETTEXT_PACKAGE);
#endif
parse_command_line_options(&argc, &argv);

Expand Down Expand Up @@ -1233,6 +1201,11 @@ gint main(gint argc, gchar **argv)
* tell other components, mainly plugins, that startup is complete */
g_idle_add_full(G_PRIORITY_LOW, send_startup_complete, NULL, NULL);

#ifdef MAC_INTEGRATION
/* OS X application ready - has to be called before entering main loop */
gtkosx_application_ready(gtkosx_application_get());
#endif

gtk_main();
return 0;
}
Expand Down
23 changes: 4 additions & 19 deletions src/notebook.c
Expand Up @@ -419,29 +419,14 @@ static void tab_bar_menu_activate_cb(GtkMenuItem *menuitem, gpointer data)

static void on_open_in_new_window_activate(GtkMenuItem *menuitem, gpointer user_data)
{
gchar *geany_path;
GeanyDocument *doc = user_data;
gchar *doc_path;

g_return_if_fail(doc->is_valid);

geany_path = g_find_program_in_path("geany");

if (geany_path)
{
gchar *doc_path = utils_get_locale_from_utf8(doc->file_name);
gchar *argv[] = {geany_path, "-i", doc_path, NULL};
GError *err = NULL;

if (!utils_spawn_async(NULL, argv, NULL, 0, NULL, NULL, NULL, &err))
{
g_printerr("Unable to open new window: %s", err->message);
g_error_free(err);
}
g_free(doc_path);
g_free(geany_path);
}
else
g_printerr("Unable to find 'geany'");
doc_path = utils_get_locale_from_utf8(doc->file_name);
utils_start_new_geany_instance(doc_path);
g_free(doc_path);
}


Expand Down

0 comments on commit 05e19be

Please sign in to comment.