Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
KWin
Commits
489fc93f
Commit
489fc93f
authored
Jun 26, 2020
by
Aleix Pol Gonzalez
🐧
Committed by
Aleix Pol Gonzalez
Oct 09, 2020
Browse files
keystates: use the qtwaylandscanner instead of having the boilerplate
parent
c9c05c38
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/wayland/CMakeLists.txt
View file @
489fc93f
...
...
@@ -222,7 +222,7 @@ ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
BASENAME wl-eglstream-controller
)
ecm_add_wayland_server_protocol
(
SERVER_LIB_SRCS
ecm_add_
qt
wayland_server_protocol
(
SERVER_LIB_SRCS
PROTOCOL
${
PLASMA_WAYLAND_PROTOCOLS_DIR
}
/keystate.xml
BASENAME keystate
)
...
...
src/wayland/keystate_interface.cpp
View file @
489fc93f
...
...
@@ -5,73 +5,46 @@
*/
#include
"keystate_interface.h"
#include
"global_p.h"
#include
"display.h"
#include
<QDebug>
#include
<QVector>
#include
<wayland-server.h>
#include
<wayland-keystate-server-protocol.h>
#include
<qwayland-server-keystate.h>
namespace
KWaylandServer
{
class
KeyStateInterface
::
Private
:
public
Global
::
Private
static
const
quint32
s_version
=
1
;
class
KeyStateInterfacePrivate
:
public
QtWaylandServer
::
org_kde_kwin_keystate
{
public:
Private
(
Display
*
d
)
:
Global
::
Private
(
d
,
&
org_kde_kwin_keystate
_interface
,
s_version
)
KeyStateInterface
Private
(
Display
*
d
)
:
QtWaylandServer
::
org_kde_kwin_keystate
(
*
d
,
s_version
)
{}
void
bind
(
wl_client
*
client
,
uint32_t
version
,
uint32_t
id
)
override
{
auto
c
=
display
->
getConnection
(
client
);
wl_resource
*
resource
=
c
->
createResource
(
&
org_kde_kwin_keystate_interface
,
qMin
(
version
,
s_version
),
id
);
if
(
!
resource
)
{
wl_client_post_no_memory
(
client
);
return
;
void
org_kde_kwin_keystate_fetchStates
(
Resource
*
resource
)
override
{
for
(
int
i
=
0
;
i
<
m_keyStates
.
count
();
++
i
)
{
send_stateChanged
(
resource
->
handle
,
i
,
m_keyStates
[
i
]);
}
wl_resource_set_implementation
(
resource
,
&
s_interface
,
this
,
unbind
);
m_resources
<<
resource
;
}
static
void
unbind
(
wl_resource
*
resource
)
{
auto
*
d
=
reinterpret_cast
<
Private
*>
(
wl_resource_get_user_data
(
resource
));
d
->
m_resources
.
removeAll
(
resource
);
}
static
void
fetchStatesCallback
(
struct
wl_client
*/
*
client
*/
,
struct
wl_resource
*
resource
)
{
auto
s
=
reinterpret_cast
<
KeyStateInterface
::
Private
*>
(
wl_resource_get_user_data
(
resource
));
for
(
int
i
=
0
;
i
<
s
->
m_keyStates
.
count
();
++
i
)
org_kde_kwin_keystate_send_stateChanged
(
resource
,
i
,
s
->
m_keyStates
[
i
]);
}
static
const
quint32
s_version
;
QVector
<
wl_resource
*>
m_resources
;
QVector
<
State
>
m_keyStates
=
QVector
<
State
>
(
3
,
Unlocked
);
static
const
struct
org_kde_kwin_keystate_interface
s_interface
;
QVector
<
KeyStateInterface
::
State
>
m_keyStates
=
QVector
<
KeyStateInterface
::
State
>
(
3
,
KeyStateInterface
::
Unlocked
);
};
const
quint32
KeyStateInterface
::
Private
::
s_version
=
1
;
KeyStateInterface
::
KeyStateInterface
(
Display
*
d
,
QObject
*
parent
)
:
Global
(
new
Private
(
d
),
parent
)
:
QObject
(
parent
)
,
d
(
new
KeyStateInterfacePrivate
(
d
))
{}
KeyStateInterface
::~
KeyStateInterface
()
=
default
;
const
struct
org_kde_kwin_keystate_interface
KeyStateInterface
::
Private
::
s_interface
=
{
fetchStatesCallback
};
void
KeyStateInterface
::
setState
(
KeyStateInterface
::
Key
key
,
KeyStateInterface
::
State
state
)
{
auto
dptr
=
static_cast
<
KeyStateInterface
::
Private
*>
(
d
.
data
());
dptr
->
m_keyStates
[
int
(
key
)]
=
state
;
d
->
m_keyStates
[
int
(
key
)]
=
state
;
for
(
auto
r
:
qAsConst
(
dptr
->
m_
resource
s
))
{
org_kde_kwin_keystate_
send_stateChanged
(
r
,
int
(
key
),
int
(
state
));
for
(
auto
r
:
d
->
resource
Map
(
))
{
d
->
send_stateChanged
(
r
->
handle
,
int
(
key
),
int
(
state
));
}
}
...
...
src/wayland/keystate_interface.h
View file @
489fc93f
...
...
@@ -8,20 +8,20 @@
#define KWAYLAND_KEYSTATE_INTERFACE_H
#include
<KWaylandServer/kwaylandserver_export.h>
#include
"global.h"
#include
"resource.h"
#include
<QObject>
namespace
KWaylandServer
{
class
Display
;
class
KeyStateInterfacePrivate
;
/**
* @brief Exposes key states to wayland clients
*
* @since 5.58
**/
class
KWAYLANDSERVER_EXPORT
KeyStateInterface
:
public
Global
class
KWAYLANDSERVER_EXPORT
KeyStateInterface
:
public
QObject
{
Q_OBJECT
public:
...
...
@@ -46,7 +46,7 @@ private:
explicit
KeyStateInterface
(
Display
*
display
,
QObject
*
parent
=
nullptr
);
friend
class
Display
;
class
Private
;
QScopedPointer
<
KeyStateInterface
Private
>
d
;
};
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment