Merge lp:~widelands-dev/widelands/handle_apple_mouse_quirks into lp:widelands

Proposed by SirVer
Status: Merged
Merged at revision: 6573
Proposed branch: lp:~widelands-dev/widelands/handle_apple_mouse_quirks
Merge into: lp:widelands
Diff against target: 238 lines (+75/-50)
5 files modified
src/editor/editorinteractive.cc (+16/-8)
src/editor/editorinteractive.h (+4/-1)
src/wlapplication.cc (+48/-31)
src/wlapplication.h (+7/-0)
src/wui/mapview.cc (+0/-10)
To merge this branch: bzr merge lp:~widelands-dev/widelands/handle_apple_mouse_quirks
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+164796@code.launchpad.net

Description of the change

Try to handle apple mouse quirks in only one place and not in many. I will merge in a few days when i hear nothing back :).

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/editorinteractive.cc'
2--- src/editor/editorinteractive.cc 2013-03-08 14:17:14 +0000
3+++ src/editor/editorinteractive.cc 2013-05-20 19:44:30 +0000
4@@ -50,6 +50,7 @@
5 Interactive_Base(e, g_options.pull_section("global")),
6 m_need_save(false),
7 m_realtime(WLApplication::get()->get_time()),
8+ m_left_mouse_button_is_down(false),
9 m_history(m_undo, m_redo),
10
11 #define INIT_BUTTON(picture, name, tooltip) \
12@@ -272,18 +273,27 @@
13 set_need_save(true);
14 }
15
16+bool Editor_Interactive::handle_mouserelease(Uint8 btn, int32_t x, int32_t y) {
17+ if (btn == SDL_BUTTON_LEFT) {
18+ m_left_mouse_button_is_down = false;
19+ }
20+ return Interactive_Base::handle_mouserelease(btn, x, y);
21+}
22+
23+bool Editor_Interactive::handle_mousepress(Uint8 btn, int32_t x, int32_t y) {
24+ if (btn == SDL_BUTTON_LEFT) {
25+ m_left_mouse_button_is_down = true;
26+ }
27+ return Interactive_Base::handle_mousepress(btn, x, y);
28+}
29+
30 /// Needed to get freehand painting tools (hold down mouse and move to edit).
31 void Editor_Interactive::set_sel_pos(Widelands::Node_and_Triangle<> const sel) {
32 bool const target_changed =
33 tools.current().operates_on_triangles() ?
34 sel.triangle != get_sel_pos().triangle : sel.node != get_sel_pos().node;
35 Interactive_Base::set_sel_pos(sel);
36- int32_t mask = SDL_BUTTON_LMASK;
37-#ifdef __APPLE__
38- // workaround for SDLs middle button emulation
39- mask |= SDL_BUTTON_MMASK;
40-#endif
41- if (target_changed and (SDL_GetMouseState(0, 0) & mask))
42+ if (target_changed and m_left_mouse_button_is_down)
43 map_clicked(true);
44 }
45
46@@ -310,7 +320,6 @@
47
48 }
49
50-
51 void Editor_Interactive::toolsize_menu_btn() {
52 if (m_toolsizemenu.window)
53 delete m_toolsizemenu.window;
54@@ -318,7 +327,6 @@
55 new Editor_Toolsize_Menu(*this, m_toolsizemenu);
56 }
57
58-
59 void Editor_Interactive::set_sel_radius_and_update_menu(uint32_t const val) {
60 if (UI::UniqueWindow * const w = m_toolsizemenu.window)
61 ref_cast<Editor_Toolsize_Menu, UI::UniqueWindow>(*w).update(val);
62
63=== modified file 'src/editor/editorinteractive.h'
64--- src/editor/editorinteractive.h 2013-02-10 19:36:24 +0000
65+++ src/editor/editorinteractive.h 2013-05-20 19:44:30 +0000
66@@ -65,8 +65,10 @@
67 virtual void set_sel_pos(Widelands::Node_and_Triangle<>);
68 void set_sel_radius_and_update_menu(uint32_t);
69
70- // gets called when a keyboard event occurs
71+ // Handle UI elements.
72 bool handle_key(bool down, SDL_keysym);
73+ bool handle_mousepress(Uint8 btn, int32_t x, int32_t y);
74+ bool handle_mouserelease(Uint8 btn, int32_t x, int32_t y);
75
76 struct Tools {
77 Tools()
78@@ -140,6 +142,7 @@
79 std::vector<Player_References> m_player_tribe_references;
80
81 int32_t m_realtime;
82+ bool m_left_mouse_button_is_down;
83
84 Editor_History m_history;
85
86
87=== modified file 'src/wlapplication.cc'
88--- src/wlapplication.cc 2013-04-20 20:20:34 +0000
89+++ src/wlapplication.cc 2013-05-20 19:44:30 +0000
90@@ -258,6 +258,7 @@
91 m_game_type (NONE),
92 journal (0),
93 m_mouse_swapped (false),
94+m_faking_middle_mouse_button(false),
95 m_mouse_position (0, 0),
96 m_mouse_locked (0),
97 m_mouse_compensate_warp(0, 0),
98@@ -680,39 +681,10 @@
99 cb->key(ev.type == SDL_KEYDOWN, ev.key.keysym);
100 }
101 break;
102+
103 case SDL_MOUSEBUTTONDOWN:
104- if (cb and cb->mouse_press) {
105- if (m_mouse_swapped) {
106- switch (ev.button.button) {
107- case SDL_BUTTON_LEFT:
108- ev.button.button = SDL_BUTTON_RIGHT;
109- break;
110- case SDL_BUTTON_RIGHT:
111- ev.button.button = SDL_BUTTON_LEFT;
112- break;
113- default:;
114- }
115- }
116- assert(ev.button.state == SDL_PRESSED);
117- cb->mouse_press(ev.button.button, ev.button.x, ev.button.y);
118- }
119- break;
120 case SDL_MOUSEBUTTONUP:
121- if (cb and cb->mouse_release) {
122- if (m_mouse_swapped) {
123- switch (ev.button.button) {
124- case SDL_BUTTON_LEFT:
125- ev.button.button = SDL_BUTTON_RIGHT;
126- break;
127- case SDL_BUTTON_RIGHT:
128- ev.button.button = SDL_BUTTON_LEFT;
129- break;
130- default:;
131- }
132- }
133- assert(ev.button.state == SDL_RELEASED);
134- cb->mouse_release(ev.button.button, ev.button.x, ev.button.y);
135- }
136+ _handle_mousebutton(ev, cb);
137 break;
138
139 case SDL_MOUSEMOTION:
140@@ -733,6 +705,51 @@
141 }
142 }
143
144+/*
145+ * Capsule repetitive code for mouse buttons
146+ */
147+void WLApplication::_handle_mousebutton
148+ (SDL_Event & ev, InputCallback const * cb)
149+{
150+ if (m_mouse_swapped) {
151+ switch (ev.button.button) {
152+ case SDL_BUTTON_LEFT:
153+ ev.button.button = SDL_BUTTON_RIGHT;
154+ break;
155+ case SDL_BUTTON_RIGHT:
156+ ev.button.button = SDL_BUTTON_LEFT;
157+ break;
158+ }
159+ }
160+
161+#ifdef __APPLE__
162+ // On Mac, SDL does middle mouse button emulation (alt+left). This
163+ // interferes with the editor, which is using alt+left click for
164+ // third tool. So if we ever see a middle mouse button on Mac,
165+ // check if any ALT Key is pressed and if, treat it like a left
166+ // mouse button.
167+ if
168+ (ev.button.button == SDL_BUTTON_MIDDLE and
169+ (get_key_state(SDLK_LALT) || get_key_state(SDLK_RALT)))
170+ {
171+ ev.button.button = SDL_BUTTON_LEFT;
172+ m_faking_middle_mouse_button = true;
173+ }
174+#endif
175+
176+ if (ev.type == SDL_MOUSEBUTTONDOWN && cb and cb->mouse_press)
177+ cb->mouse_press(ev.button.button, ev.button.x, ev.button.y);
178+ else if (ev.type == SDL_MOUSEBUTTONUP) {
179+ if (cb and cb->mouse_release) {
180+ if (ev.button.button == SDL_BUTTON_MIDDLE and m_faking_middle_mouse_button) {
181+ cb->mouse_release(SDL_BUTTON_LEFT, ev.button.x, ev.button.y);
182+ m_faking_middle_mouse_button = false;
183+ }
184+ cb->mouse_release(ev.button.button, ev.button.x, ev.button.y);
185+ }
186+ }
187+}
188+
189 /**
190 * Return the current time, in milliseconds
191 * \todo Use our internally defined time type
192
193=== modified file 'src/wlapplication.h'
194--- src/wlapplication.h 2013-02-10 20:07:27 +0000
195+++ src/wlapplication.h 2013-05-20 19:44:30 +0000
196@@ -269,6 +269,10 @@
197 ///True if left and right mouse button should be swapped
198 bool m_mouse_swapped;
199
200+ /// When apple is involved, the middle mouse button is sometimes send, even
201+ /// if it wasn't pressed. We try to revert this and this helps.
202+ bool m_faking_middle_mouse_button;
203+
204 ///The current position of the mouse pointer
205 Point m_mouse_position;
206
207@@ -309,6 +313,9 @@
208 ///created already. NULL otherwise.
209 ///\note This is private on purpose. Read the class documentation.
210 static WLApplication * the_singleton;
211+
212+ void _handle_mousebutton(SDL_Event &, InputCallback const *);
213+
214 };
215
216 #endif
217
218=== modified file 'src/wui/mapview.cc'
219--- src/wui/mapview.cc 2013-02-10 19:36:24 +0000
220+++ src/wui/mapview.cc 2013-05-20 19:44:30 +0000
221@@ -159,17 +159,7 @@
222 bool Map_View::handle_mousepress
223 (Uint8 const btn, int32_t const x, int32_t const y)
224 {
225-#ifdef __APPLE__
226- // SDL does on Mac hardcoded middle mouse button emulation (alt+left).
227- // This interferes with the editor, which is using alt+left click for third
228- // tool. So just handle middle mouse button like left one.
229- // TODO This should be handled in a more general way someplace else. What
230- // TODO kind of stupid idea is it to hardcode something like that in SDL?
231- // TODO Sometimes, people are funny....
232- if (btn == SDL_BUTTON_MIDDLE || btn == SDL_BUTTON_LEFT)
233-#else
234 if (btn == SDL_BUTTON_LEFT)
235-#endif
236 {
237 stop_dragging();
238 track_sel(Point(x, y));

Subscribers

People subscribed via source and target branches

to status/vote changes: