Greetings, personally I was not so happy about the existing Alt+Tab in Window
Maker as I was greatly used to GNOME/KDE/Windows and couldn't find myself to
switch. I modifed the code and made an option "AltTabLastFocus" (disabled by
default). I didn't add anything to WPrefs.app. This patch is based off the
Debian wmaker sources in lenny so line numbers might not match, or the base
might be out of date. When enabled, this patch will make the alt+tab dialog use
the last focus order rather than the window creation order. Have fun.
Patch is below (if attachment does not work):
======================================================================
diff -u WindowMaker-0.92.0.old/src/actions.c WindowMaker-0.92.0/src/actions.c
--- WindowMaker-0.92.0.old/src/actions.c 2009-12-30 21:18:49.000000000
-0500
+++ WindowMaker-0.92.0/src/actions.c 2009-12-30 20:56:42.000000000 -0500
@@ -183,6 +183,8 @@
/* if this is not the focused window focus it */
if (focused!=wwin) {
+ wwin->LastActiveTime = time(NULL);
+
/* change the focus window list order */
if (wPreferences.windows_cycling ) {
/* swap wwin and focused */
diff -u WindowMaker-0.92.0.old/src/defaults.c WindowMaker-0.92.0/src/defaults.c
--- WindowMaker-0.92.0.old/src/defaults.c 2009-12-30 21:18:49.000000000
-0500
+++ WindowMaker-0.92.0/src/defaults.c 2009-12-30 20:56:42.000000000 -0500
@@ -863,6 +863,11 @@
},
{"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
NULL, getCursor, setCursor
+ },
+
+ // Steven Gawroriski ([email protected]) <December 30, 2009> -- Alt+Tab
using last focus time instead of creation order
+ {"AltTabLastFocus", "NO", NULL,
+ &wPreferences.alttablastfocus, getBool, NULL
}
};
diff -u WindowMaker-0.92.0.old/src/switchpanel.c
WindowMaker-0.92.0/src/switchpanel.c
--- WindowMaker-0.92.0.old/src/switchpanel.c 2004-10-30 03:16:04.000000000
-0400
+++ WindowMaker-0.92.0/src/switchpanel.c 2009-12-30 20:52:14.000000000
-0500
@@ -401,33 +401,102 @@
static WMArray *makeWindowListArray(WScreen *scr, WWindow *curwin, int
workspace,
int include_unmapped)
{
+#define MAXLISTWINDOWS 256 // I shouldn't do this but, that is ALOT of
windows on a single workspace!
+
WMArray *windows= WMCreateArray(10);
int fl;
WWindow *wwin;
+ int i, j, k, l;
+ WWindow* WinList[MAXLISTWINDOWS];
- for (fl= 0; fl < 2; fl++) {
- for (wwin= curwin; wwin; wwin= wwin->prev) {
- if (((!fl && canReceiveFocus(wwin) > 0) || (fl &&
canReceiveFocus(wwin) < 0)) &&
- (!WFLAGP(wwin, skip_window_list) ||
wwin->flags.internal_window) &&
- (wwin->flags.mapped || include_unmapped)) {
- WMAddToArray(windows, wwin);
- }
- }
- wwin = curwin;
- /* start over from the beginning of the list */
- while (wwin->next)
- wwin = wwin->next;
-
- for (wwin= curwin; wwin && wwin != curwin; wwin= wwin->prev) {
- if (((!fl && canReceiveFocus(wwin) > 0) || (fl &&
canReceiveFocus(wwin) < 0)) &&
- (!WFLAGP(wwin, skip_window_list) ||
wwin->flags.internal_window) &&
- (wwin->flags.mapped || include_unmapped)) {
- WMAddToArray(windows, wwin);
- }
- }
- }
+ // Steven Gawroriski <December 30, 2009> -- Alt+Tab by last focus time
+ /* The GNOME/Windows/KDE Way */
+ if (wPreferences.alttablastfocus)
+ {
+ // Steven Gawroriski ([email protected]) <December 30, 2009>
--
+ // OK, from what I can tell, the loop seems to run twice.
+ // The first one appears to go through every window before
this window and
+ // adds it to the window list. It then goes back to the
current window and
+ // adds everything after it. The first run gets windows that
can recieve
+ // input focus, then the second run gets windows that cannot
recieve focus.
+ // In reality, the real windows way to do this is to sort
windows by last
+ // activate (or focus time). Applications that appear first
are ones that
+ // were activated later, and older window activations appear
later.
+ //
+ //
+ // If we have 4 windows A, B, C, and D:
+ // Window A activates at 200 seconds
+ // Window B at 300 seconds
+ // window C at 400 seconds
+ // window D at 500 seconds
+ // Alt-Tab Order: D, C, B, and A
+
+ /* Clear List */
+ memset(WinList, 0, sizeof(WinList));
+
+ /* Copy pointers to array */
+ i = 0;
+
+ // Add these windows up
+ for (wwin = curwin; wwin; wwin = wwin->prev)
+ if (i < MAXLISTWINDOWS)
+ if ((canReceiveFocus(wwin) > 0) &&
(!WFLAGP(wwin, skip_window_list) || wwin->flags.internal_window) &&
(wwin->flags.mapped || include_unmapped))
+ WinList[i++] = wwin;
+
+ // Sort Windows -- We could use a faster sorting algorithm but
I don't believe it is needed, maybe on slower PCs with
+ // more windows.
+ for (j = 0; j < i; j++)
+ {
+ // Set smallest to first
+ l = j;
+
+ // Find smallest
+ for (k = j + 1; k < i; k++)
+ if (WinList[k]->LastActiveTime >
WinList[l]->LastActiveTime)
+ l = k;
+
+ // Swap
+ if (l != j)
+ {
+ wwin = WinList[j];
+ WinList[j] = WinList[l];
+ WinList[l] = wwin;
+ }
+ }
+
+ /* Add to window list */
+ for (j = 0; j < i; j++)
+ WMAddToArray(windows, WinList[j]);
+ }
+
+ /* The Standard Way */
+ else
+ {
+ for (fl= 0; fl < 2; fl++) {
+ for (wwin= curwin; wwin; wwin= wwin->prev) {
+ if (((!fl && canReceiveFocus(wwin) > 0) || (fl &&
canReceiveFocus(wwin) < 0)) &&
+ (!WFLAGP(wwin, skip_window_list) ||
wwin->flags.internal_window) &&
+ (wwin->flags.mapped || include_unmapped)) {
+ WMAddToArray(windows, wwin);
+ }
+ }
+ wwin = curwin;
+ /* start over from the beginning of the list */
+ while (wwin->next)
+ wwin = wwin->next;
+
+ for (wwin= curwin; wwin && wwin != curwin; wwin=
wwin->prev) {
+ if (((!fl && canReceiveFocus(wwin) > 0) || (fl &&
canReceiveFocus(wwin) < 0)) &&
+ (!WFLAGP(wwin, skip_window_list) ||
wwin->flags.internal_window) &&
+ (wwin->flags.mapped || include_unmapped)) {
+ WMAddToArray(windows, wwin);
+ }
+ }
+ }
+ }
return windows;
+#undef MAXLISTWINDOWS
}
diff -u WindowMaker-0.92.0.old/src/window.c WindowMaker-0.92.0/src/window.c
--- WindowMaker-0.92.0.old/src/window.c 2005-06-30 20:56:11.000000000 -0400
+++ WindowMaker-0.92.0/src/window.c 2009-12-30 17:20:14.000000000 -0500
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
/* For getting mouse wheel mappings from WINGs */
#include <WINGs/WINGsP.h>
@@ -1583,6 +1584,8 @@
int foo;
wwin = wWindowCreate();
+
+ wwin->LastActiveTime = 0;//time(NULL);
WMAddNotificationObserver(appearanceObserver, wwin,
WNWindowAppearanceSettingsChanged, wwin);
diff -u WindowMaker-0.92.0.old/src/window.h WindowMaker-0.92.0/src/window.h
--- WindowMaker-0.92.0.old/src/window.h 2005-06-30 20:05:43.000000000 -0400
+++ WindowMaker-0.92.0/src/window.h 2009-12-30 20:45:39.000000000 -0500
@@ -316,6 +316,9 @@
RImage *net_icon_image;
Atom type;
#endif
+
+ // Steven Gawroriski ([email protected]) <December 30, 2009> --
Alt+Tab using last focus time instead of creation order
+ unsigned long LastActiveTime;
} WWindow;
diff -u WindowMaker-0.92.0.old/src/WindowMaker.h
WindowMaker-0.92.0/src/WindowMaker.h
--- WindowMaker-0.92.0.old/src/WindowMaker.h 2004-10-24 21:48:39.000000000
-0400
+++ WindowMaker-0.92.0/src/WindowMaker.h 2009-12-30 20:43:16.000000000
-0500
@@ -486,6 +486,9 @@
unsigned int nopolling:1; /* don't poll for defaults changes */
unsigned int restarting:2;
} flags; /* internal flags */
+
+ // Steven Gawroriski ([email protected]) <December 30, 2009> -- Alt+Tab
using last focus time instead of creation order
+ char alttablastfocus;
} WPreferences;
======================================================================
diff -u WindowMaker-0.92.0.old/src/actions.c WindowMaker-0.92.0/src/actions.c
--- WindowMaker-0.92.0.old/src/actions.c 2009-12-30 21:18:49.000000000 -0500
+++ WindowMaker-0.92.0/src/actions.c 2009-12-30 20:56:42.000000000 -0500
@@ -183,6 +183,8 @@
/* if this is not the focused window focus it */
if (focused!=wwin) {
+ wwin->LastActiveTime = time(NULL);
+
/* change the focus window list order */
if (wPreferences.windows_cycling ) {
/* swap wwin and focused */
diff -u WindowMaker-0.92.0.old/src/defaults.c WindowMaker-0.92.0/src/defaults.c
--- WindowMaker-0.92.0.old/src/defaults.c 2009-12-30 21:18:49.000000000 -0500
+++ WindowMaker-0.92.0/src/defaults.c 2009-12-30 20:56:42.000000000 -0500
@@ -863,6 +863,11 @@
},
{"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
NULL, getCursor, setCursor
+ },
+
+ // Steven Gawroriski ([email protected]) <December 30, 2009> -- Alt+Tab using last focus time instead of creation order
+ {"AltTabLastFocus", "NO", NULL,
+ &wPreferences.alttablastfocus, getBool, NULL
}
};
diff -u WindowMaker-0.92.0.old/src/switchpanel.c WindowMaker-0.92.0/src/switchpanel.c
--- WindowMaker-0.92.0.old/src/switchpanel.c 2004-10-30 03:16:04.000000000 -0400
+++ WindowMaker-0.92.0/src/switchpanel.c 2009-12-30 20:52:14.000000000 -0500
@@ -401,33 +401,102 @@
static WMArray *makeWindowListArray(WScreen *scr, WWindow *curwin, int workspace,
int include_unmapped)
{
+#define MAXLISTWINDOWS 256 // I shouldn't do this but, that is ALOT of windows on a single workspace!
+
WMArray *windows= WMCreateArray(10);
int fl;
WWindow *wwin;
+ int i, j, k, l;
+ WWindow* WinList[MAXLISTWINDOWS];
- for (fl= 0; fl < 2; fl++) {
- for (wwin= curwin; wwin; wwin= wwin->prev) {
- if (((!fl && canReceiveFocus(wwin) > 0) || (fl && canReceiveFocus(wwin) < 0)) &&
- (!WFLAGP(wwin, skip_window_list) || wwin->flags.internal_window) &&
- (wwin->flags.mapped || include_unmapped)) {
- WMAddToArray(windows, wwin);
- }
- }
- wwin = curwin;
- /* start over from the beginning of the list */
- while (wwin->next)
- wwin = wwin->next;
-
- for (wwin= curwin; wwin && wwin != curwin; wwin= wwin->prev) {
- if (((!fl && canReceiveFocus(wwin) > 0) || (fl && canReceiveFocus(wwin) < 0)) &&
- (!WFLAGP(wwin, skip_window_list) || wwin->flags.internal_window) &&
- (wwin->flags.mapped || include_unmapped)) {
- WMAddToArray(windows, wwin);
- }
- }
- }
+ // Steven Gawroriski <December 30, 2009> -- Alt+Tab by last focus time
+ /* The GNOME/Windows/KDE Way */
+ if (wPreferences.alttablastfocus)
+ {
+ // Steven Gawroriski ([email protected]) <December 30, 2009> --
+ // OK, from what I can tell, the loop seems to run twice.
+ // The first one appears to go through every window before this window and
+ // adds it to the window list. It then goes back to the current window and
+ // adds everything after it. The first run gets windows that can recieve
+ // input focus, then the second run gets windows that cannot recieve focus.
+ // In reality, the real windows way to do this is to sort windows by last
+ // activate (or focus time). Applications that appear first are ones that
+ // were activated later, and older window activations appear later.
+ //
+ //
+ // If we have 4 windows A, B, C, and D:
+ // Window A activates at 200 seconds
+ // Window B at 300 seconds
+ // window C at 400 seconds
+ // window D at 500 seconds
+ // Alt-Tab Order: D, C, B, and A
+
+ /* Clear List */
+ memset(WinList, 0, sizeof(WinList));
+
+ /* Copy pointers to array */
+ i = 0;
+
+ // Add these windows up
+ for (wwin = curwin; wwin; wwin = wwin->prev)
+ if (i < MAXLISTWINDOWS)
+ if ((canReceiveFocus(wwin) > 0) && (!WFLAGP(wwin, skip_window_list) || wwin->flags.internal_window) && (wwin->flags.mapped || include_unmapped))
+ WinList[i++] = wwin;
+
+ // Sort Windows -- We could use a faster sorting algorithm but I don't believe it is needed, maybe on slower PCs with
+ // more windows.
+ for (j = 0; j < i; j++)
+ {
+ // Set smallest to first
+ l = j;
+
+ // Find smallest
+ for (k = j + 1; k < i; k++)
+ if (WinList[k]->LastActiveTime > WinList[l]->LastActiveTime)
+ l = k;
+
+ // Swap
+ if (l != j)
+ {
+ wwin = WinList[j];
+ WinList[j] = WinList[l];
+ WinList[l] = wwin;
+ }
+ }
+
+ /* Add to window list */
+ for (j = 0; j < i; j++)
+ WMAddToArray(windows, WinList[j]);
+ }
+
+ /* The Standard Way */
+ else
+ {
+ for (fl= 0; fl < 2; fl++) {
+ for (wwin= curwin; wwin; wwin= wwin->prev) {
+ if (((!fl && canReceiveFocus(wwin) > 0) || (fl && canReceiveFocus(wwin) < 0)) &&
+ (!WFLAGP(wwin, skip_window_list) || wwin->flags.internal_window) &&
+ (wwin->flags.mapped || include_unmapped)) {
+ WMAddToArray(windows, wwin);
+ }
+ }
+ wwin = curwin;
+ /* start over from the beginning of the list */
+ while (wwin->next)
+ wwin = wwin->next;
+
+ for (wwin= curwin; wwin && wwin != curwin; wwin= wwin->prev) {
+ if (((!fl && canReceiveFocus(wwin) > 0) || (fl && canReceiveFocus(wwin) < 0)) &&
+ (!WFLAGP(wwin, skip_window_list) || wwin->flags.internal_window) &&
+ (wwin->flags.mapped || include_unmapped)) {
+ WMAddToArray(windows, wwin);
+ }
+ }
+ }
+ }
return windows;
+#undef MAXLISTWINDOWS
}
diff -u WindowMaker-0.92.0.old/src/window.c WindowMaker-0.92.0/src/window.c
--- WindowMaker-0.92.0.old/src/window.c 2005-06-30 20:56:11.000000000 -0400
+++ WindowMaker-0.92.0/src/window.c 2009-12-30 17:20:14.000000000 -0500
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
/* For getting mouse wheel mappings from WINGs */
#include <WINGs/WINGsP.h>
@@ -1583,6 +1584,8 @@
int foo;
wwin = wWindowCreate();
+
+ wwin->LastActiveTime = 0;//time(NULL);
WMAddNotificationObserver(appearanceObserver, wwin,
WNWindowAppearanceSettingsChanged, wwin);
diff -u WindowMaker-0.92.0.old/src/window.h WindowMaker-0.92.0/src/window.h
--- WindowMaker-0.92.0.old/src/window.h 2005-06-30 20:05:43.000000000 -0400
+++ WindowMaker-0.92.0/src/window.h 2009-12-30 20:45:39.000000000 -0500
@@ -316,6 +316,9 @@
RImage *net_icon_image;
Atom type;
#endif
+
+ // Steven Gawroriski ([email protected]) <December 30, 2009> -- Alt+Tab using last focus time instead of creation order
+ unsigned long LastActiveTime;
} WWindow;
diff -u WindowMaker-0.92.0.old/src/WindowMaker.h WindowMaker-0.92.0/src/WindowMaker.h
--- WindowMaker-0.92.0.old/src/WindowMaker.h 2004-10-24 21:48:39.000000000 -0400
+++ WindowMaker-0.92.0/src/WindowMaker.h 2009-12-30 20:43:16.000000000 -0500
@@ -486,6 +486,9 @@
unsigned int nopolling:1; /* don't poll for defaults changes */
unsigned int restarting:2;
} flags; /* internal flags */
+
+ // Steven Gawroriski ([email protected]) <December 30, 2009> -- Alt+Tab using last focus time instead of creation order
+ char alttablastfocus;
} WPreferences;