← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1808169-disable-focus into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/bug-1808169-disable-focus into lp:widelands.

Commit message:
Allowing hotkey usage while windows are open.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1808169 in widelands: "scrolling not possible with arrow keys"
  https://bugs.launchpad.net/widelands/+bug/1808169

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1808169-disable-focus/+merge/361097

Allowing to use arrow keys while windows (e.g., ware statistics) are open.

Changed two points:
- The UI::Panel no longer grabs the keyboard focus when it is clicked but shouldn't grab it
- Some components (buttons, slider, checkbox) no longer accept the keyboard focus. I don't know why they ever did so, though. It possibly was connected to the Panel being able to switch between components with the Tab key. But since nearly no component handles any keys, I guess it is no (big) loss. But still my main problem with this merge request is: Does someone knows about or finds a functionality that breaks due to the no longer applied keyboard focus?
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1808169-disable-focus into lp:widelands.
=== modified file 'src/ui_basic/button.cc'
--- src/ui_basic/button.cc	2018-12-13 07:24:01 +0000
+++ src/ui_basic/button.cc	2018-12-18 20:42:33 +0000
@@ -60,7 +60,8 @@
      title_image_(title_image),
      background_style_(g_gr->styles().button_style(init_style)) {
 	set_thinks(false);
-	set_can_focus(true);
+	// Don't allow focus
+	assert(!get_can_focus());
 }
 
 Button::Button  //  for textual buttons. If h = 0, h will resize according to the font's height.
@@ -143,8 +144,6 @@
 	if (enabled_ == on)
 		return;
 
-	set_can_focus(on);
-
 	// disabled buttons should look different...
 	if (on)
 		enabled_ = true;
@@ -316,7 +315,6 @@
 		return false;
 
 	if (enabled_) {
-		focus();
 		grab_mouse(true);
 		pressed_ = true;
 		if (repeating_) {

=== modified file 'src/ui_basic/checkbox.cc'
--- src/ui_basic/checkbox.cc	2018-12-13 07:24:01 +0000
+++ src/ui_basic/checkbox.cc	2018-12-18 20:42:33 +0000
@@ -50,7 +50,6 @@
 	uint16_t h = pic->height();
 	set_desired_size(w, h);
 	set_size(w, h);
-	set_can_focus(true);
 	set_flags(Has_Custom_Picture, true);
 }
 
@@ -98,7 +97,6 @@
  * Args: enabled  true if the checkbox should be enabled, false otherwise
  */
 void Statebox::set_enabled(bool const enabled) {
-	set_can_focus(enabled);
 	if (((flags_ & Is_Enabled) > 1) && enabled)
 		return;
 
@@ -177,7 +175,6 @@
  */
 bool Statebox::handle_mousepress(const uint8_t btn, int32_t, int32_t) {
 	if (btn == SDL_BUTTON_LEFT && (flags_ & Is_Enabled)) {
-		focus();
 		clicked();
 		return true;
 	}

=== modified file 'src/ui_basic/panel.cc'
--- src/ui_basic/panel.cc	2018-12-13 07:24:01 +0000
+++ src/ui_basic/panel.cc	2018-12-18 20:42:33 +0000
@@ -528,7 +528,7 @@
  * \return true if the mouseclick was processed, false otherwise
  */
 bool Panel::handle_mousepress(const uint8_t btn, int32_t, int32_t) {
-	if (btn == SDL_BUTTON_LEFT) {
+	if (btn == SDL_BUTTON_LEFT && get_can_focus()) {
 		focus();
 	}
 	return false;

=== modified file 'src/ui_basic/slider.cc'
--- src/ui_basic/slider.cc	2018-12-13 07:24:01 +0000
+++ src/ui_basic/slider.cc	2018-12-18 20:42:33 +0000
@@ -78,7 +78,7 @@
      bar_size_(bar_size),
      cursor_size_(cursor_size) {
 	set_thinks(false);
-	set_can_focus(true);
+	assert(!get_can_focus());
 	calculate_cursor_position();
 }
 
@@ -205,7 +205,6 @@
 	if (enabled_ == enabled)
 		return;
 
-	set_can_focus(enabled);
 	enabled_ = enabled;
 	if (!enabled) {
 		pressed_ = false;
@@ -402,7 +401,6 @@
 	if (btn != SDL_BUTTON_LEFT)
 		return false;
 
-	focus();
 	if (x >= cursor_pos_ && x <= cursor_pos_ + cursor_size_) {
 		//  click on cursor
 		cursor_pressed(x);
@@ -469,7 +467,6 @@
 	if (btn != SDL_BUTTON_LEFT)
 		return false;
 
-	focus();
 	if (y >= cursor_pos_ && y <= cursor_pos_ + cursor_size_) {
 		//  click on cursor
 		cursor_pressed(y);


Follow ups