← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1618557-keycode into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1618557-keycode into lp:widelands.

Commit message:
Replaced get_key_state with SDL_GetModState() to fix keyboard mappings. PAtch by Steven De Herdt.
Fixed reset zoom with Ctrl+0 in editor.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1618557 in widelands: "Swapped keyboard keys not always recognized"
  https://bugs.launchpad.net/widelands/+bug/1618557

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1618557-keycode/+merge/311870
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1618557-keycode into lp:widelands.
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc	2016-11-20 11:13:03 +0000
+++ src/editor/editorinteractive.cc	2016-11-26 07:35:41 +0000
@@ -108,7 +108,7 @@
 	toolsizemenu_.open_window = [this] { new EditorToolsizeMenu(*this, toolsizemenu_); };
 
 	add_toolbar_button(
-		"wui/editor/editor_menu_player_menu", "players", _("Players"), &playermenu_, true);
+	   "wui/editor/editor_menu_player_menu", "players", _("Players"), &playermenu_, true);
 	playermenu_.open_window = [this] {
 		select_tool(tools_->set_starting_pos, EditorTool::First);
 		new EditorPlayerMenu(*this, playermenu_);
@@ -257,7 +257,7 @@
 
 void EditorInteractive::exit() {
 	if (need_save_) {
-		if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL)) {
+		if (SDL_GetModState() & KMOD_CTRL) {
 			end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
 		} else {
 			UI::WLMessageBox mmb(this, _("Unsaved Map"),
@@ -369,8 +369,10 @@
 			handled = true;
 			break;
 		case SDLK_0:
-			set_sel_radius_and_update_menu(9);
-			handled = true;
+			if (!(code.mod & KMOD_CTRL)) {
+				set_sel_radius_and_update_menu(9);
+				handled = true;
+			}
 			break;
 
 		case SDLK_LSHIFT:

=== modified file 'src/editor/ui_menus/categorized_item_selection_menu.h'
--- src/editor/ui_menus/categorized_item_selection_menu.h	2016-10-06 14:32:33 +0000
+++ src/editor/ui_menus/categorized_item_selection_menu.h	2016-11-26 07:35:41 +0000
@@ -148,7 +148,7 @@
 	//  TODO(unknown): This code is erroneous. It checks the current key state. What it
 	//  needs is the key state at the time the mouse was clicked. See the
 	//  usage comment for get_key_state.
-	const bool multiselect = get_key_state(SDL_SCANCODE_LCTRL) | get_key_state(SDL_SCANCODE_RCTRL);
+	const bool multiselect = SDL_GetModState() & KMOD_CTRL;
 	if (!t && (!multiselect || tool_->get_nr_enabled() == 1))
 		checkboxes_[n]->set_state(true);
 	else {

=== modified file 'src/editor/ui_menus/tool_place_bob_options_menu.cc'
--- src/editor/ui_menus/tool_place_bob_options_menu.cc	2016-10-16 09:31:42 +0000
+++ src/editor/ui_menus/tool_place_bob_options_menu.cc	2016-11-26 07:35:41 +0000
@@ -106,7 +106,7 @@
 	//  TODO(unknown): This code is erroneous. It checks the current key state. What it
 	//  TODO(unknown): needs is the key state at the time the mouse was clicked. See the
 	//  TODO(unknown): usage comment for get_key_state.
-	const bool multiselect = get_key_state(SDL_SCANCODE_LCTRL) | get_key_state(SDL_SCANCODE_RCTRL);
+	const bool multiselect = SDL_GetModState() & KMOD_CTRL;
 	if (!t && (!multiselect || pit_.get_nr_enabled() == 1)) {
 		checkboxes_[n]->set_state(true);
 		return;

=== modified file 'src/ui_basic/window.cc'
--- src/ui_basic/window.cc	2016-10-25 08:11:31 +0000
+++ src/ui_basic/window.cc	2016-11-26 07:35:41 +0000
@@ -367,9 +367,7 @@
 	//  TODO(unknown): This code is erroneous. It checks the current key state. What it
 	//  needs is the key state at the time the mouse was clicked. See the
 	//  usage comment for get_key_state.
-	if (((get_key_state(SDL_SCANCODE_LCTRL) | get_key_state(SDL_SCANCODE_RCTRL)) &&
-	     btn == SDL_BUTTON_LEFT) ||
-	    btn == SDL_BUTTON_MIDDLE)
+	if ((SDL_GetModState() & KMOD_CTRL && btn == SDL_BUTTON_LEFT) || btn == SDL_BUTTON_MIDDLE)
 		is_minimal() ? restore() : minimize();
 	else if (btn == SDL_BUTTON_LEFT) {
 		dragging_ = true;

=== modified file 'src/wui/actionconfirm.cc'
--- src/wui/actionconfirm.cc	2016-08-04 15:49:05 +0000
+++ src/wui/actionconfirm.cc	2016-11-26 07:35:41 +0000
@@ -187,8 +187,7 @@
 
 	if (todestroy && building && iaplayer().can_act(building->owner().player_number()) &&
 	    (building->get_playercaps() & Widelands::Building::PCap_Bulldoze)) {
-		game.send_player_bulldoze(
-		   *todestroy, get_key_state(SDL_SCANCODE_LCTRL) << get_key_state(SDL_SCANCODE_RCTRL));
+		game.send_player_bulldoze(*todestroy, SDL_GetModState() & KMOD_CTRL);
 	}
 
 	die();

=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc	2016-10-24 14:04:00 +0000
+++ src/wui/buildingwindow.cc	2016-11-26 07:35:41 +0000
@@ -317,7 +317,7 @@
 ===============
 */
 void BuildingWindow::act_bulldoze() {
-	if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL)) {
+	if (SDL_GetModState() & KMOD_CTRL) {
 		if (building_.get_playercaps() & Widelands::Building::PCap_Bulldoze)
 			igbase().game().send_player_bulldoze(building_);
 	} else {
@@ -331,7 +331,7 @@
 ===============
 */
 void BuildingWindow::act_dismantle() {
-	if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL)) {
+	if (SDL_GetModState() & KMOD_CTRL) {
 		if (building_.get_playercaps() & Widelands::Building::PCap_Dismantle)
 			igbase().game().send_player_dismantle(building_);
 	} else {
@@ -375,7 +375,7 @@
 ===============
 */
 void BuildingWindow::act_enhance(Widelands::DescriptionIndex id) {
-	if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL)) {
+	if (SDL_GetModState() & KMOD_CTRL) {
 		if (building_.get_playercaps() & Widelands::Building::PCap_Enhancable)
 			igbase().game().send_player_enhance_building(building_, id);
 	} else {

=== modified file 'src/wui/fieldaction.cc'
--- src/wui/fieldaction.cc	2016-10-26 06:54:00 +0000
+++ src/wui/fieldaction.cc	2016-11-26 07:35:41 +0000
@@ -605,18 +605,17 @@
 	upcast(InteractivePlayer, iaplayer, &ibase());
 
 	if (upcast(Widelands::Flag, flag, node_.field->get_immovable())) {
+		bool ctrl_pressed = SDL_GetModState() & KMOD_CTRL;
 		if (Building* const building = flag->get_building()) {
 			if (building->get_playercaps() & Building::PCap_Bulldoze) {
-				if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL)) {
-					game->send_player_bulldoze(
-					   *flag, get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL));
+				if (ctrl_pressed) {
+					game->send_player_bulldoze(*flag, ctrl_pressed);
 				} else {
 					show_bulldoze_confirm(*iaplayer, *building, flag);
 				}
 			}
 		} else {
-			game->send_player_bulldoze(
-			   *flag, get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL));
+			game->send_player_bulldoze(*flag, ctrl_pressed);
 		}
 	}
 }
@@ -656,8 +655,7 @@
 	Widelands::EditorGameBase& egbase = ibase().egbase();
 	if (upcast(Widelands::Road, road, egbase.map().get_immovable(node_))) {
 		upcast(Game, game, &ibase().egbase());
-		game->send_player_bulldoze(
-		   *road, get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL));
+		game->send_player_bulldoze(*road, SDL_GetModState() & KMOD_CTRL);
 	}
 	okdialog();
 }

=== modified file 'src/wui/game_options_menu.cc'
--- src/wui/game_options_menu.cc	2016-10-26 06:54:00 +0000
+++ src/wui/game_options_menu.cc	2016-11-26 07:35:41 +0000
@@ -130,7 +130,7 @@
 }
 
 void GameOptionsMenu::clicked_exit_game() {
-	if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL)) {
+	if (SDL_GetModState() & KMOD_CTRL) {
 		igb_.end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
 	} else {
 		new GameOptionsMenuExitConfirmBox(*get_parent(), igb_);

=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc	2016-11-20 08:08:18 +0000
+++ src/wui/interactive_base.cc	2016-11-26 07:35:41 +0000
@@ -502,15 +502,14 @@
 		else
 			egbase().get_player(road_build_player_)->build_road(*new Widelands::Path(*buildroad_));
 
-		if (allow_user_input() &&
-		    (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL))) {
+		if (allow_user_input() && (SDL_GetModState() & KMOD_CTRL)) {
 			//  place flags
 			const Map& map = egbase().map();
 			const std::vector<Coords>& c_vector = buildroad_->get_coords();
 			std::vector<Coords>::const_iterator const first = c_vector.begin() + 2;
 			std::vector<Coords>::const_iterator const last = c_vector.end() - 2;
 
-			if (get_key_state(SDL_SCANCODE_LSHIFT) || get_key_state(SDL_SCANCODE_RSHIFT)) {
+			if (SDL_GetModState() & KMOD_SHIFT) {
 				for //  start to end
 					(std::vector<Coords>::const_iterator it = first;
 					 it <= last;

=== modified file 'src/wui/quicknavigation.cc'
--- src/wui/quicknavigation.cc	2016-10-24 20:56:32 +0000
+++ src/wui/quicknavigation.cc	2016-11-26 07:35:41 +0000
@@ -89,9 +89,7 @@
 		unsigned int which = key.sym - SDLK_0;
 		assert(which < 10);
 
-		bool ctrl = WLApplication::get()->get_key_state(SDL_SCANCODE_LCTRL) ||
-		            WLApplication::get()->get_key_state(SDL_SCANCODE_RCTRL);
-		if (ctrl) {
+		if (key.mod & KMOD_CTRL) {
 			set_landmark(which, current_);
 		} else {
 			if (landmarks_[which].set) {

=== modified file 'src/wui/shipwindow.cc'
--- src/wui/shipwindow.cc	2016-10-24 14:04:00 +0000
+++ src/wui/shipwindow.cc	2016-11-26 07:35:41 +0000
@@ -261,7 +261,7 @@
 
 /// Sink the ship if confirmed
 void ShipWindow::act_sink() {
-	if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL)) {
+	if (SDL_GetModState() & KMOD_CTRL) {
 		igbase_.game().send_player_sink_ship(ship_);
 	} else {
 		show_ship_sink_confirm(dynamic_cast<InteractivePlayer&>(igbase_), ship_);
@@ -275,7 +275,7 @@
 
 /// Cancel expedition if confirmed
 void ShipWindow::act_cancel_expedition() {
-	if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL)) {
+	if (SDL_GetModState() & KMOD_CTRL) {
 		igbase_.game().send_player_cancel_expedition_ship(ship_);
 	} else {
 		show_ship_cancel_expedition_confirm(dynamic_cast<InteractivePlayer&>(igbase_), ship_);


Follow ups