Clean up Tomboy's code
authorIra W. Snyder <devel@irasnyder.com>
Fri, 25 Jan 2008 02:06:50 +0000 (18:06 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Fri, 25 Jan 2008 02:06:50 +0000 (18:06 -0800)
This removes the unused tomboyutil code, as well as using a GTK+ function
to get the accelerator names. This reduces our code size quite a lot.

Code size reduction: (for a stripped, non-debug build)
before:            43468 bytes
remove tomboyutil: 43372 bytes
remove egg-code:   39256 bytes

So we save a total of 4212 bytes. Pretty good.

Makefile
eggaccelerators.c
eggaccelerators.h
tomboykeybinder.c
tomboykeybinder.h
tomboyutil.c [deleted file]
tomboyutil.h [deleted file]

index 0ab9090..534a45e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ ALL_LIBS=`pkg-config --libs gtk+-2.0 vte dbus-glib-1`
 
 all: tilda
 
-tilda: tilda.o tilda-controller.o tilda-window.o tilda-terminal.o tomboykeybinder.o tomboyutil.o eggaccelerators.o
+tilda: tilda.o tilda-controller.o tilda-window.o tilda-terminal.o tomboykeybinder.o eggaccelerators.o
        $(GCC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(ALL_LIBS)
 
 tilda.o: tilda.c tilda.h
@@ -36,9 +36,6 @@ tilda-terminal.o: tilda-terminal.c tilda-terminal.h tilda-terminal.xml
 tomboykeybinder.o: tomboykeybinder.c tomboykeybinder.h
        $(GCC) $(CFLAGS) -c -o $@ $< $(ALL_CFLAGS)
 
-tomboyutil.o: tomboyutil.c tomboyutil.h
-       $(GCC) $(CFLAGS) -c -o $@ $< $(ALL_CFLAGS)
-
 eggaccelerators.o: eggaccelerators.c eggaccelerators.h
        $(GCC) $(CFLAGS) -c -o $@ $< $(ALL_CFLAGS)
 
index ca63e78..be39bdc 100644 (file)
@@ -47,6 +47,7 @@ typedef struct
 
 const EggModmap* egg_keymap_get_modmap (GdkKeymap *keymap);
 
+#if 0
 static inline gboolean
 is_alt (const gchar *string)
 {
@@ -459,6 +460,7 @@ egg_virtual_accelerator_name (guint                  accelerator_key,
 
   return accelerator;
 }
+#endif
 
 void
 egg_keymap_resolve_virtual_modifiers (GdkKeymap              *keymap,
@@ -489,6 +491,7 @@ egg_keymap_resolve_virtual_modifiers (GdkKeymap              *keymap,
   *concrete_mods = concrete;
 }
 
+#if 0
 void
 egg_keymap_virtualize_modifiers (GdkKeymap              *keymap,
                                  GdkModifierType         concrete_mods,
@@ -536,6 +539,7 @@ egg_keymap_virtualize_modifiers (GdkKeymap              *keymap,
   
   *virtual_mods = virtual;
 }
+#endif
 
 static void
 reload_modmap (GdkKeymap *keymap,
index e4df317..8b624f8 100644 (file)
@@ -68,18 +68,22 @@ typedef enum
 
 } EggVirtualModifierType;
 
+#if 0
 gboolean egg_accelerator_parse_virtual        (const gchar            *accelerator,
                                                guint                  *accelerator_key,
                                                EggVirtualModifierType *accelerator_mods);
+#endif
 void     egg_keymap_resolve_virtual_modifiers (GdkKeymap              *keymap,
                                                EggVirtualModifierType  virtual_mods,
                                                GdkModifierType        *concrete_mods);
+#if 0
 void     egg_keymap_virtualize_modifiers      (GdkKeymap              *keymap,
                                                GdkModifierType         concrete_mods,
                                                EggVirtualModifierType *virtual_mods);
 
 gchar* egg_virtual_accelerator_name (guint                  accelerator_key,
                                      EggVirtualModifierType accelerator_mods);
+#endif
 
 G_END_DECLS
 
index b29e2a1..cea1725 100644 (file)
@@ -94,10 +94,16 @@ do_grab_key (Binding *binding)
        if (keymap == NULL || rootwin == NULL)
                return FALSE;
 
+       gtk_accelerator_parse (binding->keystring, &keysym, &virtual_mods);
+
+       if (keysym == 0 && virtual_mods == 0)
+               return FALSE;
+#if 0
        if (!egg_accelerator_parse_virtual (binding->keystring, 
                                            &keysym, 
                                            &virtual_mods))
                return FALSE;
+#endif
 
        TRACE (g_print ("Got accel %d, %d\n", keysym, virtual_mods));
 
@@ -283,6 +289,7 @@ tomboy_keybinder_unbind (const char           *keystring,
        }
 }
 
+#if 0
 /* 
  * From eggcellrenderkeys.c.
  */
@@ -311,6 +318,7 @@ tomboy_keybinder_is_modifier (guint keycode)
 
        return retval;
 }
+#endif
 
 guint32
 tomboy_keybinder_get_current_event_time (void)
index 0516eea..02b50ca 100644 (file)
@@ -6,7 +6,7 @@
 
 G_BEGIN_DECLS
 
-typedef void (* TomboyBindkeyHandler) (char *keystring, gpointer user_data);
+typedef void (* TomboyBindkeyHandler) (gchar *keystring, gpointer user_data);
 
 void tomboy_keybinder_init   (void);
 
@@ -17,7 +17,9 @@ gboolean tomboy_keybinder_bind (const char           *keystring,
 void tomboy_keybinder_unbind   (const char           *keystring,
                                TomboyBindkeyHandler  handler);
 
+#if 0
 gboolean tomboy_keybinder_is_modifier (guint keycode);
+#endif
 
 guint32 tomboy_keybinder_get_current_event_time (void);
 
diff --git a/tomboyutil.c b/tomboyutil.c
deleted file mode 100644 (file)
index 5c46ed1..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-
-
-#include <gdk/gdk.h>
-#include <gdk/gdkwindow.h>
-#include <gdk/gdkx.h>
-#include <gtk/gtk.h>
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-
-#include "tomboykeybinder.h"
-#include "tomboyutil.h"
-
-/* Uncomment the next line to print a debug trace. */
-/* #define DEBUG */
-
-#ifdef DEBUG
-#  define TRACE(x) x
-#else
-#  define TRACE(x) do {} while (FALSE);
-#endif
-
-gint
-tomboy_window_get_workspace (GtkWindow *window)
-{
-       GdkWindow *gdkwin = GTK_WIDGET (window)->window;
-       GdkAtom wm_desktop = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE);
-       GdkAtom out_type;
-       gint out_format, out_length;
-       gulong *out_val;
-       int workspace;
-
-       if (!gdk_property_get (gdkwin,
-                              wm_desktop,
-                              _GDK_MAKE_ATOM (XA_CARDINAL),
-                              0, G_MAXLONG,
-                              FALSE,
-                              &out_type,
-                              &out_format,
-                              &out_length,
-                              (guchar **) &out_val))
-               return -1;
-
-       workspace = *out_val;
-       g_free (out_val);
-
-       return workspace;
-}
-
-void
-tomboy_window_move_to_current_workspace (GtkWindow *window)
-{
-       GdkWindow *gdkwin = GTK_WIDGET (window)->window;
-       GdkWindow *rootwin = 
-               gdk_screen_get_root_window (gdk_drawable_get_screen (gdkwin));
-
-       GdkAtom current_desktop = 
-               gdk_atom_intern ("_NET_CURRENT_DESKTOP", FALSE);
-       GdkAtom wm_desktop = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE);
-       GdkAtom out_type;
-       gint out_format, out_length;
-       gulong *out_val;
-       int workspace;
-       XEvent xev;
-
-       if (!gdk_property_get (rootwin,
-                              current_desktop,
-                              _GDK_MAKE_ATOM (XA_CARDINAL),
-                              0, G_MAXLONG,
-                              FALSE,
-                              &out_type,
-                              &out_format,
-                              &out_length,
-                              (guchar **) &out_val))
-               return;
-
-       workspace = *out_val;
-       g_free (out_val);
-
-       TRACE (g_print ("Setting _NET_WM_DESKTOP to: %d\n", workspace));
-
-       xev.xclient.type = ClientMessage;
-       xev.xclient.serial = 0;
-       xev.xclient.send_event = True;
-       xev.xclient.display = GDK_WINDOW_XDISPLAY (gdkwin);
-       xev.xclient.window = GDK_WINDOW_XWINDOW (gdkwin);
-       xev.xclient.message_type = 
-               gdk_x11_atom_to_xatom_for_display(
-                       gdk_drawable_get_display (gdkwin),
-                       wm_desktop);
-       xev.xclient.format = 32;
-       xev.xclient.data.l[0] = workspace;
-       xev.xclient.data.l[1] = 0;
-       xev.xclient.data.l[2] = 0;
-
-       XSendEvent (GDK_WINDOW_XDISPLAY (rootwin),
-                   GDK_WINDOW_XWINDOW (rootwin),
-                   False,
-                   SubstructureRedirectMask | SubstructureNotifyMask,
-                   &xev);
-}
-
-static void
-tomboy_window_override_user_time (GtkWindow *window)
-{
-       guint32 ev_time = gtk_get_current_event_time();
-
-       if (ev_time == 0) {
-               /* 
-                * FIXME: Global keypresses use an event filter on the root
-                * window, which processes events before GDK sees them.
-                */
-               ev_time = tomboy_keybinder_get_current_event_time ();
-       }
-       if (ev_time == 0) {
-               gint ev_mask = gtk_widget_get_events (GTK_WIDGET(window));
-               if (!(ev_mask & GDK_PROPERTY_CHANGE_MASK)) {
-                       gtk_widget_add_events (GTK_WIDGET (window),
-                                              GDK_PROPERTY_CHANGE_MASK);
-               }
-
-               /* 
-                * NOTE: Last resort for D-BUS or other non-interactive
-                *       openings.  Causes roundtrip to server.  Lame. 
-                */
-               ev_time = gdk_x11_get_server_time (GTK_WIDGET(window)->window);
-       }
-
-       TRACE (g_print("Setting _NET_WM_USER_TIME to: %d\n", ev_time));
-       gdk_x11_window_set_user_time (GTK_WIDGET(window)->window, ev_time);
-}
-
-void
-tomboy_window_present_hardcore (GtkWindow *window)
-{
-       if (!GTK_WIDGET_REALIZED (window))
-               gtk_widget_realize (GTK_WIDGET (window));
-       else if (GTK_WIDGET_VISIBLE (window))
-               tomboy_window_move_to_current_workspace (window);
-
-       tomboy_window_override_user_time (window);
-
-       gtk_window_present (window);
-}
-
diff --git a/tomboyutil.h b/tomboyutil.h
deleted file mode 100644 (file)
index 939d326..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-
-#ifndef __TOMBOY_UTIL_H__
-#define __TOMBOY_UTIL_H__
-
-#include <gdk/gdkpixmap.h>
-#include <gtk/gtkwidget.h>
-#include <gtk/gtkwindow.h>
-
-G_BEGIN_DECLS
-
-gint tomboy_window_get_workspace (GtkWindow *window);
-
-void tomboy_window_move_to_current_workspace (GtkWindow *window);
-
-void tomboy_window_present_hardcore (GtkWindow *window);
-
-G_END_DECLS
-
-#endif /* __TOMBOY_UTIL_H__ */