From 15793868fee49ef0ab73097466df309fef2602cc Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 28 Jul 2016 23:38:17 +0200 Subject: [PATCH] Improvements for the window focus --- ChangeLog | 2 +- src/fapp.cpp | 230 ++++++++++++++++++++++++---------------------- src/fdialog.cpp | 1 + src/fmenu.cpp | 13 +++ src/fmenuitem.cpp | 3 +- src/fobject.cpp | 3 + 6 files changed, 142 insertions(+), 110 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0c674d6..a1285acb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2016-07-27 Markus Gans +2016-07-28 Markus Gans * Improvements for the window focus 2016-07-24 Markus Gans diff --git a/src/fapp.cpp b/src/fapp.cpp index 76b715a8..f39b2ac5 100644 --- a/src/fapp.cpp +++ b/src/fapp.cpp @@ -302,121 +302,135 @@ void FApplication::processKeyboardEvent() { key = modifierKeyCorrection (key); - if ( key == fc::Fckey_l ) // Ctrl-L (redraw the screen) - redraw(); - - if ( key == fc::Fkey_mouse ) + switch ( key ) { - int n; - const int len = 6; - x11_mouse[0] = fifo_buf[3]; - x11_mouse[1] = fifo_buf[4]; - x11_mouse[2] = fifo_buf[5]; - x11_mouse[3] = '\0'; + case fc::Fckey_l: // Ctrl-L (redraw the screen) + redraw(); + break; - for (n=len; n < fifo_buf_size; n++) // Remove founded entry - fifo_buf[n-len] = fifo_buf[n]; - - n = fifo_buf_size-len-1; - - for (; n < fifo_buf_size; n++) // Fill rest with '\0' - fifo_buf[n-len] = '\0'; - - input_data_pending = bool(fifo_buf[0] != '\0'); - processMouseEvent(); - } - else if ( key == fc::Fkey_extended_mouse ) - { - int n = 3; - int len = int(strlen(fifo_buf)); - - while ( n < len && n < fifo_buf_size ) - { - sgr_mouse[n-3] = fifo_buf[n]; - n++; - - if ( fifo_buf[n] == 'M' || fifo_buf[n] == 'm' ) - len = n + 1; - } - - sgr_mouse[n-3] = '\0'; - - for (n=len; n < fifo_buf_size; n++) // Remove founded entry - fifo_buf[n-len] = fifo_buf[n]; - - n = fifo_buf_size-len-1; - - for (; n < fifo_buf_size; n++) // Fill rest with '\0' - fifo_buf[n-len] = '\0'; - - input_data_pending = bool(fifo_buf[0] != '\0'); - processMouseEvent(); - } - else if ( key == fc::Fkey_urxvt_mouse ) - { - int n = 2; - int len = int(strlen(fifo_buf)); - - while ( n < len && n < fifo_buf_size ) - { - urxvt_mouse[n-2] = fifo_buf[n]; - n++; - - if ( fifo_buf[n] == 'M' || fifo_buf[n] == 'm' ) - len = n + 1; - } - - urxvt_mouse[n-2] = '\0'; - - for (n=len; n < fifo_buf_size; n++) // Remove founded entry - fifo_buf[n-len] = fifo_buf[n]; - - n = fifo_buf_size-len-1; - - for (; n < fifo_buf_size; n++) // Fill rest with '\0' - fifo_buf[n-len] = '\0'; - - input_data_pending = bool(fifo_buf[0] != '\0'); - processMouseEvent(); - } - else - { - // send key down event - FKeyEvent k_down_ev (fc::KeyDown_Event, key); - sendEvent (widget, &k_down_ev); - - // send key press event - FKeyEvent k_press_ev (fc::KeyPress_Event, key); - sendEvent (widget, &k_press_ev); - - if ( ! open_menu - && ! k_press_ev.isAccepted() - && ! k_down_ev.isAccepted() ) - { - bool accpt = false; - // switch to a specific dialog with Meta + 1..9 - if ( ! accpt ) - accpt = processDialogSwitchAccelerator(); - - // windows keyboard accelerator - if ( ! accpt ) + case fc::Fkey_mouse: { - FWidget* window = static_cast(active_window); + int n; + const int len = 6; + x11_mouse[0] = fifo_buf[3]; + x11_mouse[1] = fifo_buf[4]; + x11_mouse[2] = fifo_buf[5]; + x11_mouse[3] = '\0'; - if ( window ) - accpt = processAccelerator (window); + // Remove founded entry + for (n=len; n < fifo_buf_size; n++) + fifo_buf[n-len] = fifo_buf[n]; + + n = fifo_buf_size-len-1; + + // Fill rest with '\0' + for (; n < fifo_buf_size; n++) + fifo_buf[n-len] = '\0'; + + input_data_pending = bool(fifo_buf[0] != '\0'); + processMouseEvent(); } - - // global keyboard accelerator - if ( ! accpt ) + break; + + case fc::Fkey_extended_mouse: { - FWidget* root_widget = getRootWidget(); - - if ( root_widget ) - accpt = processAccelerator (root_widget); + int n = 3; + int len = int(strlen(fifo_buf)); + + while ( n < len && n < fifo_buf_size ) + { + sgr_mouse[n-3] = fifo_buf[n]; + n++; + + if ( fifo_buf[n] == 'M' || fifo_buf[n] == 'm' ) + len = n + 1; + } + + sgr_mouse[n-3] = '\0'; + + for (n=len; n < fifo_buf_size; n++) // Remove founded entry + fifo_buf[n-len] = fifo_buf[n]; + + n = fifo_buf_size-len-1; + + for (; n < fifo_buf_size; n++) // Fill rest with '\0' + fifo_buf[n-len] = '\0'; + + input_data_pending = bool(fifo_buf[0] != '\0'); + processMouseEvent(); } - } - } // end of else + break; + + case fc::Fkey_urxvt_mouse: + { + int n = 2; + int len = int(strlen(fifo_buf)); + + while ( n < len && n < fifo_buf_size ) + { + urxvt_mouse[n-2] = fifo_buf[n]; + n++; + + if ( fifo_buf[n] == 'M' || fifo_buf[n] == 'm' ) + len = n + 1; + } + + urxvt_mouse[n-2] = '\0'; + + for (n=len; n < fifo_buf_size; n++) // Remove founded entry + fifo_buf[n-len] = fifo_buf[n]; + + n = fifo_buf_size-len-1; + + for (; n < fifo_buf_size; n++) // Fill rest with '\0' + fifo_buf[n-len] = '\0'; + + input_data_pending = bool(fifo_buf[0] != '\0'); + processMouseEvent(); + } + break; + + default: + { + // send key down event + FKeyEvent k_down_ev (fc::KeyDown_Event, key); + sendEvent (widget, &k_down_ev); + + // send key press event + FKeyEvent k_press_ev (fc::KeyPress_Event, key); + sendEvent (widget, &k_press_ev); + + if ( ! open_menu + && ! k_press_ev.isAccepted() + && ! k_down_ev.isAccepted() ) + { + bool accpt = false; + // switch to a specific dialog with Meta + 1..9 + if ( ! accpt ) + accpt = processDialogSwitchAccelerator(); + + // windows keyboard accelerator + if ( ! accpt ) + { + FWidget* window = static_cast(active_window); + + if ( window ) + accpt = processAccelerator (window); + } + + // global keyboard accelerator + if ( ! accpt ) + { + FWidget* root_widget = getRootWidget(); + + if ( root_widget ) + accpt = processAccelerator (root_widget); + } + } + } + break; + + } // end of switch } fifo_offset = int(strlen(fifo_buf)); diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 3f15ffa1..da759b6b 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -1018,6 +1018,7 @@ void FDialog::activateDialog() FWidget* old_focus = FWidget::getFocusWidget(); FWidget* win_focus_widget = getWindowFocusWidget(); setActiveWindow(this); + setFocus(); if ( win_focus_widget && numOfFocusableChildren() > 1 ) { diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 3822b4e6..7abf3cf5 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -1040,6 +1040,19 @@ void FMenu::onKeyPress (FKeyEvent* ev) flush_out(); break; + case fc::Fmkey_1: + case fc::Fmkey_2: + case fc::Fmkey_3: + case fc::Fmkey_4: + case fc::Fmkey_5: + case fc::Fmkey_6: + case fc::Fmkey_7: + case fc::Fmkey_8: + case fc::Fmkey_9: + // do nothing: + // handle the dialog switch accelerator in FApplication + return; + default: break; } diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 090327c1..cfbab8ce 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -314,8 +314,9 @@ void FMenuItem::cb_destroyDialog (FWidget* widget, void* data_ptr) { FDialog* win = static_cast(widget); FMenuItem* win_item = static_cast(data_ptr); + FApplication* fapp = static_cast(getRootWidget()); - if ( win_item && win ) + if ( win_item && win && fapp && ! fapp->isQuit() ) { win_item->delAccelerator(win); win_item->delCallback(this); diff --git a/src/fobject.cpp b/src/fobject.cpp index f6aabdef..cb1c04fc 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -39,6 +39,7 @@ FObject::~FObject() // destructor if ( parentObj ) parentObj->delChild(this); + parentObj = 0; delOwnTimer(); // delete all timers of this object if ( ! has_parent && timer_list ) @@ -61,6 +62,8 @@ FObject::~FObject() // destructor ++iter; } } + + } // public methods of FObject