Patch for root menus



I made a patch for root menus of Sawfish-1.3.

* The window names or class names have codesets of the current locale,
  and GTK+-2 requires UTF-8 codesets. Thus menu item of beos-window-
  menu need to be converted into UTF-8 to show window item with its
  name localized.

* The boundary of UTF-8 multibyte characters need to be checked when
  the name is cut in abbreviate().

* I think the menu item of the window with "desktop" property set (it
  is nautilus desktop) must be skipped.

* "Application" menu in root menu seems to be obsoluted on GNOME-2, so
  I tried removing the item from the root menu.

Here is a patch, works well, I think so, with Sawfish-1.3.
--
S. TAHARA

diff -ru sawfish-1.3.orig/lisp/sawfish/wm/ext/beos-window-menu.jl sawfish-1.3/lisp/sawfish/wm/ext/beos-window-menu.jl
--- sawfish-1.3.orig/lisp/sawfish/wm/ext/beos-window-menu.jl	2002-04-21 05:59:18.000000000 +0900
+++ sawfish-1.3/lisp/sawfish/wm/ext/beos-window-menu.jl	2003-08-12 17:41:08.000000000 +0900
@@ -25,6 +25,7 @@
     (export beos-window-menu)
 
     (open rep
+	  rep.regexp
 	  sawfish.wm.windows
 	  sawfish.wm.misc
 	  sawfish.wm.custom
@@ -38,9 +39,16 @@
 
   (define (abbreviate name #!optional len)
     (unless len (setq len 20))
-    (if (> (length name) len)
-	(concat (substring name 0 len) "...")
-      name))
+    (setq name (locale-to-utf8 name))
+    (let ((namelen (length name)))
+      (let loop ((idx len))
+	(cond ((>= idx namelen)
+	       name)
+	      ((string-match "[\200-\277]" (substring name idx (1+ idx)))
+	       ;; move to utf-8 mbchar boundary
+	       (loop (1+ idx)))
+	      (t
+	       (concat (substring name 0 idx) "..."))))))
 
   (define (make-label w)
     (let ((name (window-name w))
@@ -78,7 +86,8 @@
 	 (window-mapped-p w)
 	 (or (window-get w 'iconified)
 	     (and (not (window-get w 'window-list-skip))
-		  (not (window-get w 'ignored))))))
+		  (not (window-get w 'ignored))
+		  (not (window-get w 'desktop))))))
 
   (define (make-group-item id)
     (let loop ((menu '())
diff -ru sawfish-1.3.orig/lisp/sawfish/wm/gnome/integration.jl sawfish-1.3/lisp/sawfish/wm/gnome/integration.jl
--- sawfish-1.3.orig/lisp/sawfish/wm/gnome/integration.jl	2003-01-13 05:35:10.000000000 +0900
+++ sawfish-1.3/lisp/sawfish/wm/gnome/integration.jl	2003-08-12 16:21:53.000000000 +0900
@@ -23,7 +23,7 @@
 
     (open rep
 	  sawfish.wm.state.gnome
-	  sawfish.wm.gnome.menus
+;;	  sawfish.wm.gnome.menus	;; Perhaps obsolute in GNOME2
 	  sawfish.wm.menus
 	  sawfish.wm.custom
 	  sawfish.wm.commands.help
@@ -31,9 +31,12 @@
 
   (define-structure-alias gnome-int sawfish.wm.gnome.integration)
 
-  ;; delete the `Restart' and `Quit' items from the root menu
-  (let ((restart (rassoc '(restart) root-menu))
+  ;; delete the 'Programs', `Restart' and `Quit' items from the root menu
+  (let ((programs (rassoc 'apps-menu root-menu))
+	(restart (rassoc '(restart) root-menu))
 	(quit (rassoc '(quit) root-menu)))
+    (when programs
+      (setq root-menu (delq programs root-menu)))
     (when restart
       (setq root-menu (delq restart root-menu)))
     (when quit
diff -ru sawfish-1.3.orig/src/functions.c sawfish-1.3/src/functions.c
--- sawfish-1.3.orig/src/functions.c	2002-11-04 06:00:36.000000000 +0900
+++ sawfish-1.3/src/functions.c	2003-08-12 16:11:38.000000000 +0900
@@ -43,6 +43,8 @@
 #include "sawmill.h"
 #include <X11/Xatom.h>
 
+#include <glib.h>
+
 /* Number of outstanding server grabs made; only when this is zero is
    the server ungrabbed. */
 static int server_grabs;
@@ -1313,6 +1315,31 @@
     }
 }
 
+DEFUN("locale-to-utf8", Flocale_to_utf8, Slocale_to_utf8,
+      (repv src), rep_Subr1)
+{
+    gsize r, w;
+    u_char *utf8str;
+    repv res;
+
+    rep_DECLARE1 (src, rep_STRINGP);
+
+    utf8str = g_locale_to_utf8 (rep_STR (src), -1, &r, &w, NULL);
+    if (utf8str == NULL) {
+	return src;
+    }
+
+    res = rep_make_string (w + 1);
+    if (!res)
+	return rep_mem_error ();
+
+    strncpy (rep_STR (res), utf8str, w);
+    rep_STR (res)[w] = '\0';
+
+    g_free (utf8str);
+    return res;
+}
+
 
 /* initialisation */
 
@@ -1353,6 +1380,7 @@
     rep_ADD_SUBR(Shead_dimensions);
     rep_ADD_SUBR(Shead_offset);
     rep_ADD_SUBR(Sdisplay_message);
+    rep_ADD_SUBR(Slocale_to_utf8);
     rep_pop_structure (tem);
 
     tem = rep_push_structure ("sawfish.wm.events");



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