FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/desktop/DesktopPosixApplicationLaunch.cpp at master · pearsonca/rstudio · GitHub
pearsonca
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
desktop
/
DesktopPosixApplicationLaunch.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
226 lines (191 loc) · 7.41 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
desktop
/
DesktopPosixApplicationLaunch.cpp
Copy path
File metadata and controls
226 lines (191 loc) · 7.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* DesktopPosixApplicationLaunch.cpp
*
* Copyright (C) 2009-18 by RStudio, PBC
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
"
DesktopApplicationLaunch.hpp
"
#
include
"
DesktopPosixApplication.hpp
"
#
include
"
DesktopOptions.hpp
"
#
include
<
core/system/Environment.hpp
>
#
include
<
core/r_util/RUserData.hpp
>
#
include
<
QKeyEvent
>
#
include
<
QMouseEvent
>
namespace
rstudio
{
namespace
desktop
{
namespace
{
PosixApplication*
app
()
{
return
qobject_cast<PosixApplication*>(qApp);
}
//
helper for swapping Ctrl, Meta modifiers
//
https://bugreports.qt.io/browse/QTBUG-51293
class
MacEventFilter
:
public
QObject
{
public:
explicit
MacEventFilter
(QObject* parent)
: QObject(parent)
{
}
protected:
bool
eventFilter
(QObject* object, QEvent* event)
override
{
//
Fix issue with malformed mouse events that can be emitted when the
//
application is focused through either a very fast mouse click, or a
//
trackpad click. in such cases, the 'primary' mouse button is
//
registered in event->button(), but event->buttons() is Qt::NoButton.
//
when this occurs, Qt fails to delegate the mouse event to the
//
sub-widget hosting the web page, causing the mouse event to
//
effectively be dropped. this leads to a mousedown event without a
//
companion mouseup event, effectively leaving the event handler (often
//
Ace) stuck in a pseudo-drag state, which causes all sorts of funky
//
behavior. see:
//
//
https://github.com/rstudio/rstudio/issues/5107
//
https://bugreports.qt.io/browse/QTBUG-77125
//
//
for some more details.
if
(event->
type
() == QEvent::MouseButtonPress ||
event->
type
() == QEvent::MouseButtonRelease)
{
QMouseEvent* mouseEvent =
static_cast
<QMouseEvent*>(event);
if
(mouseEvent->
buttons
() == Qt::NoButton)
{
QMouseEvent* fixedMouseEvent =
new
QMouseEvent
(
mouseEvent->
type
(),
mouseEvent->
localPos
(),
mouseEvent->
windowPos
(),
mouseEvent->
screenPos
(),
mouseEvent->
button
(),
mouseEvent->
button
(),
mouseEvent->
modifiers
());
QCoreApplication::postEvent
(object, fixedMouseEvent);
return
true
;
}
}
if
(event->
type
() == QEvent::KeyPress)
{
auto
* keyEvent =
static_cast
<QKeyEvent*>(event);
auto
modifiers = keyEvent->
modifiers
();
//
Through a series of unfortunate events, Qt fails to translate
//
Ctrl keypresses to Meta, and vice versa. pressing Ctrl, therefore,
//
sends a key event where the 'ctrlKey' property is true, but the
//
associated keyCode is 91, and the key pressed is 'Meta'. Ace fails
//
to discover a printable key with keycode 91, so tries calling
//
String.fromCharCode() to figure out what character should be used
//
instead; this key happens to be '['. This leads to Ace receiving the
//
equivalent of a Ctrl+[ keypress, which Ace then interprets as an
//
outdent request (with the default keybindings).
//
//
We'll just swallow bare modifier keypresses since we don't actually
//
use these for anything (they're only ever handled in conjunction
//
with other keypresses; ie, as modifiers)
if
(keyEvent->
key
() == Qt::Key_Meta &&
modifiers == Qt::
META
)
{
return
true
;
}
else
if
(keyEvent->
key
() == Qt::Key_Control &&
modifiers == Qt::
CTRL
)
{
return
true
;
}
//
convert Backtab into Shift+Tab -- this is necessary for focus
//
switching as the default browser behavior doesn't understand
//
the Qt 'Backtab' key event
if
(keyEvent->
key
() == Qt::Key_Backtab)
{
auto
* event =
new
QKeyEvent
(
QEvent::KeyPress,
Qt::Key_Tab,
modifiers | Qt::ShiftModifier);
QCoreApplication::postEvent
(object, event);
return
true
;
}
}
return
QObject::eventFilter
(object, event);
}
};
}
//
anonymous namespace
ApplicationLaunch::ApplicationLaunch
() :
QWidget
(
nullptr
),
pMainWindow_
(
nullptr
)
{
connect
(
app
(),
SIGNAL
(
messageReceived
(QString)),
this
,
SIGNAL
(
openFileRequest
(QString)));
launchEnv_ =
QProcessEnvironment::systemEnvironment
();
}
void
ApplicationLaunch::init
(QString appName,
int
& argc,
char
* argv[],
boost::scoped_ptr<QApplication>* ppApp,
boost::scoped_ptr<ApplicationLaunch>* ppAppLaunch)
{
//
Immediately stuffed into scoped_ptr
auto
* pSingleApplication =
new
PosixApplication
(appName, argc, argv);
//
create app launch instance
PosixApplication::setApplicationName
(appName);
ppApp->
reset
(pSingleApplication);
ppAppLaunch->
reset
(
new
ApplicationLaunch
());
pSingleApplication->
setAppLauncher
(ppAppLaunch->
get
());
//
connect app open file signal to app launch
connect
(
app
(),
SIGNAL
(
openFileRequest
(QString)),
ppAppLaunch->
get
(),
SIGNAL
(
openFileRequest
(QString)));
#
ifdef
Q_OS_MAC
pSingleApplication->
installEventFilter
(
new
MacEventFilter
(pSingleApplication));
#
endif
}
void
ApplicationLaunch::setActivationWindow
(QWidget* pWindow)
{
pMainWindow_ = pWindow;
app
()->
setActivationWindow
(pWindow,
true
);
}
void
ApplicationLaunch::activateWindow
()
{
app
()->
activateWindow
();
}
void
ApplicationLaunch::attemptToRegisterPeer
()
{
//
side-effect of is running is to try to register ourselves as a peer
app
()->
isRunning
();
}
bool
ApplicationLaunch::sendMessage
(QString filename)
{
return
app
()->
sendMessage
(filename);
}
QString
ApplicationLaunch::startupOpenFileRequest
()
const
{
return
app
()->
startupOpenFileRequest
();
}
void
ApplicationLaunch::launchRStudio
(
const
std::vector<std::string>& args,
const
std::string& initialDir)
{
QStringList argList;
for
(
const
std::string& arg : args)
{
argList.
append
(
QString::fromStdString
(arg));
}
QString exePath =
QString::fromUtf8
(
desktop::options
().
executablePath
().
getAbsolutePath
().
c_str
());
//
temporarily restore the library path to the one we were launched with
std::string ldPath =
core::system::getenv
(
"
LD_LIBRARY_PATH
"
);
core::system::setenv
(
"
LD_LIBRARY_PATH
"
,
launchEnv_.
value
(
QString::fromUtf8
(
"
LD_LIBRARY_PATH
"
)).
toStdString
());
//
set environment variable indicating initial launch dir
core::system::setenv
(
kRStudioInitialWorkingDir
, initialDir);
//
start RStudio detached
QProcess::startDetached
(exePath, argList);
//
restore environment
core::system::setenv
(
"
LD_LIBRARY_PATH
"
, ldPath);
core::system::unsetenv
(
kRStudioInitialWorkingDir
);
}
}
//
namespace desktop
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL