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
6504e067
Commit
6504e067
authored
Nov 26, 2014
by
Martin Flöser
Browse files
KeyboardInterface inherits Resource
parent
99598167
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/wayland/keyboard_interface.cpp
View file @
6504e067
...
...
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include
"keyboard_interface.h"
#include
"resource_p.h"
#include
"display.h"
#include
"seat_interface.h"
#include
"surface_interface.h"
...
...
@@ -35,11 +36,10 @@ namespace KWayland
namespace
Server
{
class
KeyboardInterface
::
Private
class
KeyboardInterface
::
Private
:
public
Resource
::
Private
{
public:
Private
(
SeatInterface
*
s
);
void
createInterfae
(
wl_client
*
client
,
wl_resource
*
parentResource
,
uint32_t
id
);
Private
(
SeatInterface
*
s
,
wl_resource
*
parentResource
,
KeyboardInterface
*
q
);
void
sendKeymap
();
void
sendKeymap
(
int
fd
,
quint32
size
);
void
sendModifiers
();
...
...
@@ -48,22 +48,17 @@ public:
SeatInterface
*
seat
;
SurfaceInterface
*
focusedSurface
=
nullptr
;
QMetaObject
::
Connection
destroyConnection
;
wl_resource
*
resource
=
nullptr
;
private:
static
Private
*
cast
(
wl_resource
*
resource
)
{
return
reinterpret_cast
<
KeyboardInterface
::
Private
*>
(
wl_resource_get_user_data
(
resource
));
}
static
void
unbind
(
wl_resource
*
resource
);
// since version 3
static
void
releaseCallback
(
wl_client
*
client
,
wl_resource
*
resource
);
static
const
struct
wl_keyboard_interface
s_interface
;
};
KeyboardInterface
::
Private
::
Private
(
SeatInterface
*
s
)
:
seat
(
s
)
KeyboardInterface
::
Private
::
Private
(
SeatInterface
*
s
,
wl_resource
*
parentResource
,
KeyboardInterface
*
q
)
:
Resource
::
Private
(
q
,
s
,
parentResource
,
&
wl_keyboard_interface
,
&
s_interface
)
,
seat
(
s
)
{
}
...
...
@@ -71,43 +66,12 @@ const struct wl_keyboard_interface KeyboardInterface::Private::s_interface {
releaseCallback
};
KeyboardInterface
::
KeyboardInterface
(
SeatInterface
*
parent
)
:
QObject
(
parent
)
,
d
(
new
Private
(
parent
))
{
}
KeyboardInterface
::~
KeyboardInterface
()
{
if
(
d
->
resource
)
{
wl_resource_destroy
(
d
->
resource
);
}
}
void
KeyboardInterface
::
createInterfae
(
wl_client
*
client
,
wl_resource
*
parentResource
,
uint32_t
id
)
KeyboardInterface
::
KeyboardInterface
(
SeatInterface
*
parent
,
wl_resource
*
parentResource
)
:
Resource
(
new
Private
(
parent
,
parentResource
,
this
),
parent
)
{
d
->
createInterfae
(
client
,
parentResource
,
id
);
}
void
KeyboardInterface
::
Private
::
createInterfae
(
wl_client
*
client
,
wl_resource
*
parentResource
,
uint32_t
id
)
{
wl_resource
*
k
=
wl_resource_create
(
client
,
&
wl_keyboard_interface
,
wl_resource_get_version
(
parentResource
),
id
);
if
(
!
k
)
{
wl_resource_post_no_memory
(
parentResource
);
return
;
}
resource
=
k
;
wl_resource_set_implementation
(
k
,
&
s_interface
,
this
,
unbind
);
sendKeymap
();
}
void
KeyboardInterface
::
Private
::
unbind
(
wl_resource
*
resource
)
{
auto
k
=
cast
(
resource
);
k
->
resource
=
nullptr
;
}
KeyboardInterface
::~
KeyboardInterface
()
=
default
;
void
KeyboardInterface
::
Private
::
releaseCallback
(
wl_client
*
client
,
wl_resource
*
resource
)
{
...
...
@@ -117,6 +81,7 @@ void KeyboardInterface::Private::releaseCallback(wl_client *client, wl_resource
void
KeyboardInterface
::
setKeymap
(
int
fd
,
quint32
size
)
{
Q_D
();
d
->
sendKeymap
(
fd
,
size
);
}
...
...
@@ -151,6 +116,7 @@ void KeyboardInterface::Private::sendModifiers()
void
KeyboardInterface
::
setFocusedSurface
(
SurfaceInterface
*
surface
,
quint32
serial
)
{
Q_D
();
if
(
d
->
focusedSurface
)
{
wl_keyboard_send_leave
(
d
->
resource
,
serial
,
d
->
focusedSurface
->
resource
());
disconnect
(
d
->
destroyConnection
);
...
...
@@ -161,6 +127,7 @@ void KeyboardInterface::setFocusedSurface(SurfaceInterface *surface, quint32 ser
}
d
->
destroyConnection
=
connect
(
d
->
focusedSurface
,
&
QObject
::
destroyed
,
this
,
[
this
]
{
Q_D
();
d
->
focusedSurface
=
nullptr
;
}
);
...
...
@@ -180,30 +147,34 @@ void KeyboardInterface::setFocusedSurface(SurfaceInterface *surface, quint32 ser
void
KeyboardInterface
::
keyPressed
(
quint32
key
,
quint32
serial
)
{
Q_D
();
Q_ASSERT
(
d
->
focusedSurface
);
wl_keyboard_send_key
(
d
->
resource
,
serial
,
d
->
seat
->
timestamp
(),
key
,
WL_KEYBOARD_KEY_STATE_PRESSED
);
}
void
KeyboardInterface
::
keyReleased
(
quint32
key
,
quint32
serial
)
{
Q_D
();
Q_ASSERT
(
d
->
focusedSurface
);
wl_keyboard_send_key
(
d
->
resource
,
serial
,
d
->
seat
->
timestamp
(),
key
,
WL_KEYBOARD_KEY_STATE_RELEASED
);
}
void
KeyboardInterface
::
updateModifiers
(
quint32
depressed
,
quint32
latched
,
quint32
locked
,
quint32
group
,
quint32
serial
)
{
Q_D
();
Q_ASSERT
(
d
->
focusedSurface
);
d
->
sendModifiers
(
depressed
,
latched
,
locked
,
group
,
serial
);
}
SurfaceInterface
*
KeyboardInterface
::
focusedSurface
()
const
{
Q_D
();
return
d
->
focusedSurface
;
}
wl_resourc
e
*
KeyboardInterface
::
resource
()
const
KeyboardInterface
::
Privat
e
*
KeyboardInterface
::
d_func
()
const
{
return
d
->
resource
;
return
reinterpret_cast
<
Private
*>
(
d
.
data
())
;
}
}
...
...
src/wayland/keyboard_interface.h
View file @
6504e067
...
...
@@ -20,13 +20,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#ifndef WAYLAND_SERVER_KEYBOARD_INTERFACE_H
#define WAYLAND_SERVER_KEYBOARD_INTERFACE_H
#include
<QObject>
#include
<QPoint>
#include
<KWayland/Server/kwaylandserver_export.h>
struct
wl_client
;
struct
wl_resource
;
#include
"resource.h"
namespace
KWayland
{
...
...
@@ -36,18 +32,14 @@ namespace Server
class
SeatInterface
;
class
SurfaceInterface
;
class
KWAYLANDSERVER_EXPORT
KeyboardInterface
:
public
QObject
class
KWAYLANDSERVER_EXPORT
KeyboardInterface
:
public
Resource
{
Q_OBJECT
public:
virtual
~
KeyboardInterface
();
void
createInterfae
(
wl_client
*
client
,
wl_resource
*
parentResource
,
uint32_t
id
);
SurfaceInterface
*
focusedSurface
()
const
;
wl_resource
*
resource
()
const
;
private:
void
setFocusedSurface
(
SurfaceInterface
*
surface
,
quint32
serial
);
void
setKeymap
(
int
fd
,
quint32
size
);
...
...
@@ -55,10 +47,10 @@ private:
void
keyPressed
(
quint32
key
,
quint32
serial
);
void
keyReleased
(
quint32
key
,
quint32
serial
);
friend
class
SeatInterface
;
explicit
KeyboardInterface
(
SeatInterface
*
parent
);
explicit
KeyboardInterface
(
SeatInterface
*
parent
,
wl_resource
*
parentResource
);
class
Private
;
QScopedPointer
<
Private
>
d
;
Private
*
d_func
()
const
;
};
}
...
...
src/wayland/seat_interface.cpp
View file @
6504e067
...
...
@@ -276,7 +276,7 @@ KeyboardInterface *SeatInterface::Private::keyboardForSurface(SurfaceInterface *
}
for
(
auto
it
=
keyboards
.
begin
();
it
!=
keyboards
.
end
();
++
it
)
{
if
(
wl_resource_get_client
((
*
it
)
->
resource
()
)
==
*
surface
->
client
())
{
if
(
(
*
it
)
->
client
(
)
==
surface
->
client
())
{
return
(
*
it
);
}
}
...
...
@@ -365,8 +365,13 @@ void SeatInterface::Private::getKeyboardCallback(wl_client *client, wl_resource
void
SeatInterface
::
Private
::
getKeyboard
(
wl_client
*
client
,
wl_resource
*
resource
,
uint32_t
id
)
{
// TODO: only create if seat has keyboard?
KeyboardInterface
*
keyboard
=
new
KeyboardInterface
(
q
);
keyboard
->
createInterfae
(
client
,
resource
,
id
);
KeyboardInterface
*
keyboard
=
new
KeyboardInterface
(
q
,
resource
);
keyboard
->
create
(
display
->
getConnection
(
client
),
wl_resource_get_version
(
resource
),
id
);
if
(
!
keyboard
->
resource
())
{
wl_resource_post_no_memory
(
resource
);
delete
keyboard
;
return
;
}
keyboards
<<
keyboard
;
if
(
keys
.
focus
.
surface
&&
keys
.
focus
.
surface
->
client
()
->
client
()
==
client
)
{
// this is a keyboard for the currently focused keyboard surface
...
...
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