blob: 31b25067b7d85bfef858edc276617d025c72dae2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "WinEventsSDL.h"
#include "GUIUserMessages.h"
#include "ServiceBroker.h"
#include "application/AppInboundProtocol.h"
#include "application/Application.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "input/InputManager.h"
#include "input/Key.h"
#include "input/mouse/MouseStat.h"
#include "messaging/ApplicationMessenger.h"
#include "settings/DisplaySettings.h"
#include "windowing/WinSystem.h"
#include "platform/darwin/osx/CocoaInterface.h"
bool CWinEventsOSX::MessagePump()
{
SDL_Event event;
bool ret = false;
while (SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
if (!g_application.m_bStop)
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_QUIT);
break;
case SDL_ACTIVEEVENT:
//If the window was inconified or restored
if( event.active.state & SDL_APPACTIVE )
{
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
appPort->SetRenderGUI(event.active.gain != 0);
CServiceBroker::GetWinSystem()->NotifyAppActiveChange(g_application.GetRenderGUI());
}
else if (event.active.state & SDL_APPINPUTFOCUS)
{
g_application.m_AppFocused = event.active.gain != 0;
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort && g_application.m_AppFocused)
appPort->SetRenderGUI(g_application.m_AppFocused);
CServiceBroker::GetWinSystem()->NotifyAppFocusChange(g_application.m_AppFocused);
}
break;
case SDL_KEYDOWN:
{
// process any platform specific shortcuts before handing off to XBMC
if (ProcessOSXShortcuts(event))
{
ret = true;
break;
}
XBMC_Event newEvent = {};
newEvent.type = XBMC_KEYDOWN;
newEvent.key.keysym.scancode = event.key.keysym.scancode;
newEvent.key.keysym.sym = (XBMCKey) event.key.keysym.sym;
newEvent.key.keysym.unicode = event.key.keysym.unicode;
// Check if the Windows keys are down because SDL doesn't flag this.
uint16_t mod = event.key.keysym.mod;
uint8_t* keystate = SDL_GetKeyState(NULL);
if (keystate[SDLK_LSUPER] || keystate[SDLK_RSUPER])
mod |= XBMCKMOD_LSUPER;
newEvent.key.keysym.mod = (XBMCMod) mod;
// don't handle any more messages in the queue until we've handled keydown,
// if a keyup is in the queue it will reset the keypress before it is handled.
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
ret |= appPort->OnEvent(newEvent);
break;
}
case SDL_KEYUP:
{
XBMC_Event newEvent = {};
newEvent.type = XBMC_KEYUP;
newEvent.key.keysym.scancode = event.key.keysym.scancode;
newEvent.key.keysym.sym = (XBMCKey) event.key.keysym.sym;
newEvent.key.keysym.mod =(XBMCMod) event.key.keysym.mod;
newEvent.key.keysym.unicode = event.key.keysym.unicode;
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
ret |= appPort->OnEvent(newEvent);
break;
}
case SDL_MOUSEBUTTONDOWN:
{
XBMC_Event newEvent = {};
newEvent.type = XBMC_MOUSEBUTTONDOWN;
newEvent.button.button = event.button.button;
newEvent.button.x = event.button.x;
newEvent.button.y = event.button.y;
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
ret |= appPort->OnEvent(newEvent);
break;
}
case SDL_MOUSEBUTTONUP:
{
XBMC_Event newEvent = {};
newEvent.type = XBMC_MOUSEBUTTONUP;
newEvent.button.button = event.button.button;
newEvent.button.x = event.button.x;
newEvent.button.y = event.button.y;
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
ret |= appPort->OnEvent(newEvent);
break;
}
case SDL_MOUSEMOTION:
{
if (0 == (SDL_GetAppState() & SDL_APPMOUSEFOCUS))
{
CServiceBroker::GetInputManager().SetMouseActive(false);
// See CApplication::ProcessSlow() for a description as to why we call Cocoa_HideMouse.
// this is here to restore the pointer when toggling back to window mode from fullscreen.
Cocoa_ShowMouse();
break;
}
XBMC_Event newEvent = {};
newEvent.type = XBMC_MOUSEMOTION;
newEvent.motion.x = event.motion.x;
newEvent.motion.y = event.motion.y;
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
ret |= appPort->OnEvent(newEvent);
break;
}
case SDL_VIDEORESIZE:
{
// Under newer osx versions sdl is so fucked up that it even fires resize events
// that exceed the screen size (maybe some HiDP incompatibility in old SDL?)
// ensure to ignore those events because it will mess with windowed size
if((event.resize.w > CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP).iWidth) ||
(event.resize.h > CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP).iHeight))
{
break;
}
XBMC_Event newEvent = {};
newEvent.type = XBMC_VIDEORESIZE;
newEvent.resize.w = event.resize.w;
newEvent.resize.h = event.resize.h;
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
ret |= appPort->OnEvent(newEvent);
CServiceBroker::GetGUI()->GetWindowManager().MarkDirty();
break;
}
case SDL_USEREVENT:
{
XBMC_Event newEvent = {};
newEvent.type = XBMC_USEREVENT;
newEvent.user.code = event.user.code;
std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
if (appPort)
ret |= appPort->OnEvent(newEvent);
break;
}
case SDL_VIDEOEXPOSE:
CServiceBroker::GetGUI()->GetWindowManager().MarkDirty();
break;
}
memset(&event, 0, sizeof(SDL_Event));
}
return ret;
}
bool CWinEventsOSX::ProcessOSXShortcuts(SDL_Event& event)
{
static bool shift = false, cmd = false;
cmd = !!(SDL_GetModState() & (KMOD_LMETA | KMOD_RMETA ));
shift = !!(SDL_GetModState() & (KMOD_LSHIFT | KMOD_RSHIFT));
if (cmd && event.key.type == SDL_KEYDOWN)
{
char keysymbol = event.key.keysym.sym;
// if the unicode is in the ascii range
// use this instead for getting the real
// character based on the used keyboard layout
// see http://lists.libsdl.org/pipermail/sdl-libsdl.org/2004-May/043716.html
bool isControl = (event.key.keysym.mod & KMOD_CTRL) != 0;
if (!isControl && !(event.key.keysym.unicode & 0xff80))
keysymbol = event.key.keysym.unicode;
switch(keysymbol)
{
case SDLK_q: // CMD-q to quit
if (!g_application.m_bStop)
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_QUIT);
return true;
case SDLK_f: // CMD-Ctrl-f to toggle fullscreen
if (!isControl)
return false;
g_application.OnAction(CAction(ACTION_TOGGLE_FULLSCREEN));
return true;
case SDLK_s: // CMD-3 to take a screenshot
g_application.OnAction(CAction(ACTION_TAKE_SCREENSHOT));
return true;
case SDLK_h: // CMD-h to hide
CServiceBroker::GetWinSystem()->Hide();
return true;
case SDLK_m: // CMD-m to minimize
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_MINIMIZE);
return true;
default:
return false;
}
}
return false;
}
|