From 430d6e87c637971f2fcb86b32fb44f7f0b4eb8ef Mon Sep 17 00:00:00 2001 From: Bill Spitzak Date: Thu, 29 Jun 2006 07:28:43 +0000 Subject: [PATCH] Fixed release of Alt+Tab on newer fltk1 versions. Made the shortcuts work somewhat for fltk2.0, but not working completely Fixes from Bill Allombert: Typos in manpage Doubles the & signs in menus to avoid underscores The -fg switch works to set the text color everywhere Ifdef'ed out some fltk2.0-only stuff. --- Frame.C | 11 ++++++++--- Hotkeys.C | 32 ++++++++++++++++++++++++++++++-- Makefile | 2 +- Menu.C | 21 ++++++++++++++++++--- flwm.1 | 6 +++--- main.C | 39 ++++++++++++++++++++++++++------------- 6 files changed, 86 insertions(+), 25 deletions(-) diff --git a/Frame.C b/Frame.C index 9c49d93..4af2ce2 100644 --- a/Frame.C +++ b/Frame.C @@ -92,6 +92,7 @@ Frame::Frame(XWindow window, XWindowAttributes* existing) : min_w_button.callback(button_cb_static); end(); box(FL_NO_BOX); // relies on background color erasing interior + labelcolor(FL_FOREGROUND_COLOR); next = first; first = this; @@ -795,7 +796,7 @@ int Frame::activate(int warp) { XSetWindowAttributes a; a.background_pixel = fl_xpixel(FL_SELECTION_COLOR); XChangeWindowAttributes(fl_display, fl_xid(this), CWBackPixel, &a); - labelcolor(contrast(FL_BLACK, FL_SELECTION_COLOR)); + labelcolor(contrast(FL_FOREGROUND_COLOR, FL_SELECTION_COLOR)); XClearArea(fl_display, fl_xid(this), 2, 2, w()-4, h()-4, 1); #else #ifdef SHOW_CLOCK @@ -815,7 +816,7 @@ void Frame::deactivate() { XSetWindowAttributes a; a.background_pixel = fl_xpixel(FL_GRAY); XChangeWindowAttributes(fl_display, fl_xid(this), CWBackPixel, &a); - labelcolor(FL_BLACK); + labelcolor(FL_FOREGROUND_COLOR); XClearArea(fl_display, fl_xid(this), 2, 2, w()-4, h()-4, 1); #else #ifdef SHOW_CLOCK @@ -1197,7 +1198,11 @@ void Frame::show_hide_buttons() { // make sure fltk does not try to set the window size: void Frame::resize(int, int, int, int) {} // For fltk2.0: -void Frame::layout() {layout_damage(0);} +void Frame::layout() { +#if FL_MAJOR_VERSION>1 + layout_damage(0); // actually this line is not needed in newest cvs fltk2.0 +#endif +} //////////////////////////////////////////////////////////////// diff --git a/Hotkeys.C b/Hotkeys.C index 71eb339..df80930 100644 --- a/Hotkeys.C +++ b/Hotkeys.C @@ -149,8 +149,37 @@ static struct {int key; void (*func)();} keybindings[] = { #endif {0}}; +#if FL_MAJOR_VERSION > 1 +// Define missing function, this should get put in fltk2.0: +namespace fltk { +int test_shortcut(int shortcut) { + if (!shortcut) return 0; + + int shift = Fl::event_state(); + // see if any required shift flags are off: + if ((shortcut&shift) != (shortcut&0x7fff0000)) return 0; + // record shift flags that are wrong: + int mismatch = (shortcut^shift)&0x7fff0000; + // these three must always be correct: + if (mismatch&(FL_META|FL_ALT|FL_CTRL)) return 0; + + int key = shortcut & 0xffff; + + // if shift is also correct, check for exactly equal keysyms: + if (!(mismatch&(FL_SHIFT)) && unsigned(key) == Fl::event_key()) return 1; + + // try matching ascii, ignore shift: + if (key == event_text()[0]) return 1; + + // kludge so that Ctrl+'_' works (as opposed to Ctrl+'^_'): + if ((shift&FL_CTRL) && key >= 0x3f && key <= 0x5F + && event_text()[0]==(key^0x40)) return 1; + return 0; +} +} +#endif + int Handle_Hotkey() { -#if 0 for (int i = 0; keybindings[i].key; i++) { if (Fl::test_shortcut(keybindings[i].key) || (keybindings[i].key & 0xFFFF) == FL_Delete @@ -160,7 +189,6 @@ int Handle_Hotkey() { return 1; } } -#endif return 0; } diff --git a/Makefile b/Makefile index a55f135..92ac207 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ VERSION = 1.00 CXXFILES = main.C Frame.C Rotated.C Menu.C FrameWindow.C Desktop.C Hotkeys.C -LIBS = -lfltk +LIBS = MANPAGE = 1 diff --git a/Menu.C b/Menu.C index 1ab25f6..3902970 100644 --- a/Menu.C +++ b/Menu.C @@ -82,7 +82,7 @@ frame_label_draw(const Fl_Label* o, int X, int Y, int W, int H, Fl_Align align) if (h < 3) h = 3; if (y+h > SCREEN_H) y = SCREEN_H-h; if (y < 0) y = 0; - fl_color(FL_BLACK); + fl_color(FL_FOREGROUND_COLOR); if (c->state() == ICONIC) fl_rect(X+x+SCREEN_DX, Y+y+SCREEN_DX, w, h); else @@ -92,6 +92,17 @@ frame_label_draw(const Fl_Label* o, int X, int Y, int W, int H, Fl_Align align) fl_font(o->font, o->size); fl_color((Fl_Color)o->color); const char* l = f->label(); if (!l) l = "unnamed"; + // double any ampersands to turn off the underscores: + char buf[256]; + if (strchr(l,'&')) { + char* t = buf; + while (t < buf+254 && *l) { + if (*l=='&') *t++ = *l; + *t++ = *l; + } + *t = 0; + l = buf; + } fl_draw(l, X+MENU_ICON_W+3, Y, W-MENU_ICON_W-3, H, align); } @@ -282,12 +293,16 @@ init(Fl_Menu_Item& m, const char* data) m.style = 0; #endif m.label(data); +#if FL_MAJOR_VERSION > 2 + m.flags = fltk::RAW_LABEL; +#else m.flags = 0; +#endif m.labeltype(FL_NORMAL_LABEL); m.shortcut(0); m.labelfont(MENU_FONT_SLOT); m.labelsize(MENU_FONT_SIZE); - m.labelcolor(FL_BLACK); + m.labelcolor(FL_FOREGROUND_COLOR); } #if WMX_MENU_ITEMS @@ -603,7 +618,7 @@ ShowTabMenu(int tab) if (!level) menu[n].labeltype(TEXT_LABEL); #endif - int nextlev = (i==num_wmx-1)?0:strspn(wmxlist[i+1], "/")-1; + int nextlev = (i==num_wmx-1)?0:strspn(wmxlist[i+1], "/")-1; if (nextlev < level) { menu[n].callback(spawn_cb, cmd); // Close 'em off diff --git a/flwm.1 b/flwm.1 index 6fce06b..5f20124 100644 --- a/flwm.1 +++ b/flwm.1 @@ -78,7 +78,7 @@ GCC is your friend. .SH MENU ITEMS -Flwm can launch programs from it's menu. This is controlled by files +Flwm can launch programs from its menu. This is controlled by files in the directory .B ~/.wmx (this was chosen to be compatible with wmx and wm2). @@ -181,14 +181,14 @@ To switch to another desktop, pick the title of the desktop (if using the keyboard, use left arrow to go to the desktop names, move up and down to the other desktop). -If a desktop is empty you can delete it. It's sub menu will show +If a desktop is empty you can delete it. Its sub menu will show .B delete this desktop. Pick that and the desktop is gone. .B Sticky is a special "desktop": windows on it appear on all desktops. To make a window "sticky" switch to the Sticky desktop and pick the window off -it's current desktop (thus "moving" it to the Sticky desktop). To +its current desktop (thus "moving" it to the Sticky desktop). To "unstick" a window go to another desktop and pick the window off the sticky desktop menu. diff --git a/main.C b/main.C index 51ed49a..c8ac8ec 100644 --- a/main.C +++ b/main.C @@ -43,7 +43,11 @@ static int xerror_handler(Display* d, XErrorEvent* e) { class Fl_Root : public Fl_Window { int handle(int); public: - Fl_Root() : Fl_Window(0,0,Fl::w(),Fl::h()) {clear_double_buffer();} + Fl_Root() : Fl_Window(0,0,Fl::w(),Fl::h()) { +#if FL_MAJOR_VERSION > 1 + clear_double_buffer(); +#endif + } void show() { if (!shown()) Fl_X::set_xid(this, RootWindow(fl_display, fl_screen)); } @@ -108,22 +112,31 @@ static int flwm_event_handler(int e) { const XMapRequestEvent* e = &(fl_xevent->xmaprequest); (void)new Frame(e->window); return 1;} - case KeyRelease: { +#if FL_MAJOR_VERSION<2 + // this was needed for *some* earlier versions of fltk + case KeyRelease: if (!Fl::grab()) return 0; - // see if they released the alt key: - unsigned long keysym = + Fl::e_keysym = XKeycodeToKeysym(fl_display, fl_xevent->xkey.keycode, 0); - if (keysym == FL_Alt_L || keysym == FL_Alt_R) { - Fl::e_keysym = FL_Enter; -#if FL_MAJOR_VERSION>1 - return Fl::modal()->handle(FL_KEYBOARD); -#else - return Fl::grab()->handle(FL_KEYBOARD); + goto KEYUP; #endif - } - return 0;} } - } else if (e == FL_SHORTCUT) { + } else if (e == FL_KEYUP) { +#if FL_MAJOR_VERSION<2 + KEYUP: +#endif + if (!Fl::grab()) return 0; + // when alt key released, pretend they hit enter & pick menu item + if (Fl::event_key()==FL_Alt_L || Fl::event_key()==FL_Alt_R) { + Fl::e_keysym = FL_Enter; +#if FL_MAJOR_VERSION>1 + return Fl::modal()->handle(FL_KEYBOARD); +#else + return Fl::grab()->handle(FL_KEYBOARD); +#endif + } + return 0; + } else if (e == FL_SHORTCUT || e == FL_KEYBOARD) { #if FL_MAJOR_VERSION == 1 && FL_MINOR_VERSION == 0 && FL_PATCH_VERSION < 3 // make the tab keys work in the menus in older fltk's: // (they do not cycle around however, so a new fltk is a good idea)