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

[wmx] Patch for sorted list in Window Menu

Elmar Bartel - Tue May 25 19:38:53 1999

Hello *,

Following is a patch (relative to the wmx-5 sources), that
add a "sort" option for the window menu. I need a sorted window
list, since it's time too consuming to search 20-30 hidden windows
for the desired one.

========================================================================
diff -ur wmx-5/Config.C wmx-5elb/Config.C
--- wmx-5/Config.C	Wed Jan 13 11:28:43 1999
+++ wmx-5elb/Config.C	Sat May 22 20:41:15 1999
@@ -16,7 +16,7 @@
     char focus; 	// 1 = Click , 2 = Raise, 4 = Autoraise
     int  delay;
     char kbd;		// 1 = Keyboard on
-    char menu;		// 0 = no unmapped, 1 = everything
+    char menu;		// 0 = no unmapped, 1 = everything, 2 = sorted
     char feedback;	// 0 = no , 1 = yes
     char disable;	// 0 = New Window option, 1 = no New
 };  
@@ -68,6 +68,7 @@
 int  DynamicConfig::raiseDelay() { return m_impl->delay; }
 char DynamicConfig::useKeyboard() { return m_impl->kbd & 1; }
 char DynamicConfig::fullMenu() { return m_impl->menu & 1; }
+char DynamicConfig::sortMenu() { return m_impl->menu & 2; }
 char DynamicConfig::useFeedback() { return m_impl->feedback & 1; }
 char DynamicConfig::disableNew() { return m_impl->disable & 1; }
 
@@ -99,9 +100,13 @@
     do {
 	fprintf(stderr, ">%s< ",s);
 
-	if (OPTION("menu:"))
-	    if (OPTION("full")) m_impl->menu = 1;
-	    else if (OPTION("part")) m_impl->menu = 0;
+	if (OPTION("menu:")) {
+	    do {
+		if (OPTION("full")) m_impl->menu |= 1;
+		else if (OPTION("part")) m_impl->menu &= ~1;
+		else if (OPTION("sort")) m_impl->menu |= 2;
+	    } while (OPTION(","));
+	}
 
 	if (OPTION("new:"))
 	    if (OPTION("on")) m_impl->disable = 0;
diff -ur wmx-5/Config.h wmx-5elb/Config.h
--- wmx-5/Config.h	Wed Jan 13 11:28:43 1999
+++ wmx-5elb/Config.h	Sat May 22 20:25:01 1999
@@ -45,6 +45,7 @@
     int  raiseDelay();
     char useKeyboard();
     char fullMenu();
+    char sortMenu();
     char useFeedback();
     char disableNew();
 
@@ -65,6 +66,9 @@
 // List visible as well as hidden clients on the root menu?  (Visible
 // ones will be towards the bottom of the menu, flush-right.)
 #define CONFIG_EVERYTHING_ON_ROOT_MENU (dConfig.fullMenu())
+
+// Sort the entries in the window menu
+#define CONFIG_SORTED_MENU (dConfig.sortMenu())
 
 // Spawn a temporary new shell between the wm and each new process?
 #define CONFIG_EXEC_USING_SHELL   False
diff -ur wmx-5/Menu.C wmx-5elb/Menu.C
--- wmx-5/Menu.C	Wed Jan 13 11:28:43 1999
+++ wmx-5elb/Menu.C	Sat May 22 20:47:27 1999
@@ -463,22 +463,51 @@
     free(m_items);
 }
 
+static ClientList *gcl;
+static int sortitem(const void *va, const void *vb)
+{
+    const char *a = gcl->item(*(int *)va)->label();
+    const char *b = gcl->item(*(int *)vb)->label();
+    return strcmp(a, b);
+}
+static int *initPerm(ClientList &cl) {
+    int n, i;
+    int *perm;
+    n= cl.count();
+
+    perm = (int *)malloc(n * sizeof(int));
+    for (i = 0; i < n; ++i)
+     	perm[i] = i;
+    
+    if (CONFIG_SORTED_MENU) {
+	gcl = &cl;
+	qsort(perm, cl.count(), sizeof(int), sortitem);
+    }
+
+    return perm;
+}
 char **ClientMenu::getItems(int *niR, int *nhR)
 {
     int i;
     XButtonEvent *xbev = (XButtonEvent *)m_event; // KeyEvent is similar enough
 
+#define item(i)	item(perm[i])
+    int *perm;
+
+    perm = initPerm(m_windowManager->hiddenClients());
     for (i = 0; i < m_windowManager->hiddenClients().count(); ++i) {
 	if (m_windowManager->hiddenClients().item(i)->channel() ==
 	    m_windowManager->channel()) {
 	    m_clients.append(m_windowManager->hiddenClients().item(i));
 	}
     }
+    free(perm);
 
     int nh = m_clients.count();
     if (!CONFIG_DISABLE_NEW_WINDOW_COMMAND) ++nh;
 
     if (CONFIG_EVERYTHING_ON_ROOT_MENU) {
+	perm = initPerm(m_windowManager->clients());
 	for (i = 0; i < m_windowManager->clients().count(); ++i) {
 	    if (m_windowManager->clients().item(i)->isNormal() &&
 		m_windowManager->clients().item(i)->channel() ==
@@ -486,7 +515,9 @@
 		m_clients.append(m_windowManager->clients().item(i));
 	    }
 	}
+	free(perm);
     }
+#undef item
 
     int n = m_clients.count();
     if (!CONFIG_DISABLE_NEW_WINDOW_COMMAND) ++n;
========================================================================

One personal remark: I very much appreciate the special style of this
piece of SW.  But I think, configure doesn't match this style (sorry
Stefan, no objections against You!)

My change to use wmx as my standard WM inspired me to write some
historical remarks about my WM usage in the past:
        http://www.in.tum.de/~bartel/wm.html

Yours,
Elmar Bartel, RBG.
-- 
mailto:Elmar.Bartel@in.tum.de    |    fax:+49-89-289-28232  
  http://www.in.tum.de/~bartel/  |  phone:+49-89-289-22025
Windows NT is not a problem - Ignorance is a problem.


Next: