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
354857e9
Commit
354857e9
authored
Jan 20, 2022
by
Aleix Pol Gonzalez
🐧
Committed by
Aleix Pol Gonzalez
Jan 21, 2022
Browse files
mouseclick: Also decorate tablet events
BUG: 426584
parent
324b172a
Pipeline
#126496
passed with stage
in 14 minutes and 5 seconds
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
src/effects/mouseclick/mouseclick.cpp
View file @
354857e9
...
...
@@ -17,6 +17,7 @@
#include
<KGlobalAccel>
#include
<QPainter>
#include
<QTabletEvent>
#include
<cmath>
...
...
@@ -123,6 +124,12 @@ void MouseClickEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
click
->
m_frame
->
render
(
infiniteRegion
(),
frameAlpha
,
frameAlpha
);
}
}
for
(
const
auto
&
tool
:
qAsConst
(
m_tabletTools
))
{
const
int
step
=
m_ringMaxSize
*
(
1.
-
tool
.
m_pressure
);
for
(
qreal
size
=
m_ringMaxSize
;
size
>
0
;
size
-=
step
)
{
drawCircle
(
tool
.
m_color
,
tool
.
m_globalPosition
.
x
(),
tool
.
m_globalPosition
.
y
(),
size
);
}
}
paintScreenFinish
(
mask
,
region
,
data
);
}
...
...
@@ -200,6 +207,14 @@ void MouseClickEffect::repaint()
}
effects
->
addRepaint
(
dirtyRegion
);
}
if
(
!
m_tabletTools
.
isEmpty
())
{
QRegion
dirtyRegion
;
const
int
radius
=
m_ringMaxSize
+
m_lineWidth
;
for
(
const
auto
&
event
:
qAsConst
(
m_tabletTools
))
{
dirtyRegion
|=
QRect
(
event
.
m_globalPosition
.
x
()
-
radius
,
event
.
m_globalPosition
.
y
()
-
radius
,
2
*
radius
,
2
*
radius
);
}
effects
->
addRepaint
(
dirtyRegion
);
}
}
bool
MouseClickEffect
::
isReleased
(
Qt
::
MouseButtons
button
,
Qt
::
MouseButtons
buttons
,
Qt
::
MouseButtons
oldButtons
)
...
...
@@ -226,6 +241,7 @@ void MouseClickEffect::toggleEnabled()
qDeleteAll
(
m_clicks
);
m_clicks
.
clear
();
m_tabletTools
.
clear
();
for
(
int
i
=
0
;
i
<
BUTTON_COUNT
;
++
i
)
{
m_buttons
[
i
]
->
m_time
=
0
;
...
...
@@ -235,7 +251,7 @@ void MouseClickEffect::toggleEnabled()
bool
MouseClickEffect
::
isActive
()
const
{
return
m_enabled
&&
(
m_clicks
.
size
()
>
0
);
return
m_enabled
&&
(
!
m_clicks
.
isEmpty
()
||
!
m_tabletTools
.
isEmpty
()
);
}
void
MouseClickEffect
::
drawCircle
(
const
QColor
&
color
,
float
cx
,
float
cy
,
float
r
)
...
...
@@ -313,5 +329,41 @@ void MouseClickEffect::paintScreenFinishGl(int, QRegion, ScreenPaintData&)
ShaderManager
::
instance
()
->
popShader
();
}
bool
MouseClickEffect
::
tabletToolEvent
(
QTabletEvent
*
event
)
{
auto
&
tabletEvent
=
m_tabletTools
[
event
->
uniqueId
()];
if
(
!
tabletEvent
.
m_color
.
isValid
())
{
switch
(
event
->
pointerType
())
{
case
QTabletEvent
::
UnknownPointer
:
case
QTabletEvent
::
Pen
:
tabletEvent
.
m_color
=
MouseClickConfig
::
color1
();
break
;
case
QTabletEvent
::
Eraser
:
tabletEvent
.
m_color
=
MouseClickConfig
::
color2
();
break
;
case
QTabletEvent
::
Cursor
:
tabletEvent
.
m_color
=
MouseClickConfig
::
color3
();
break
;
}
}
switch
(
event
->
type
())
{
case
QEvent
::
TabletPress
:
tabletEvent
.
m_pressed
=
true
;
break
;
case
QEvent
::
TabletRelease
:
tabletEvent
.
m_pressed
=
false
;
break
;
case
QEvent
::
TabletLeaveProximity
:
m_tabletTools
.
remove
(
event
->
uniqueId
());
return
false
;
default:
break
;
}
tabletEvent
.
m_globalPosition
=
event
->
globalPos
();
tabletEvent
.
m_pressure
=
event
->
pressure
();
return
false
;
}
}
// namespace
src/effects/mouseclick/mouseclick.h
View file @
354857e9
...
...
@@ -14,6 +14,7 @@
#include
<kwinglutils.h>
#include
<KLocalizedString>
#include
<QFont>
#include
<QHash>
namespace
KWin
{
...
...
@@ -43,6 +44,15 @@ public:
}
};
class
TabletToolEvent
{
public:
QPointF
m_globalPosition
;
bool
m_pressed
=
false
;
qreal
m_pressure
=
0
;
QColor
m_color
;
};
class
MouseButton
{
public:
...
...
@@ -128,6 +138,8 @@ public:
return
m_enabled
;
}
bool
tabletToolEvent
(
QTabletEvent
*
event
)
override
;
private
Q_SLOTS
:
void
toggleEnabled
();
void
slotMouseChanged
(
const
QPoint
&
pos
,
const
QPoint
&
old
,
...
...
@@ -163,6 +175,7 @@ private:
QList
<
MouseEvent
*>
m_clicks
;
MouseButton
*
m_buttons
[
BUTTON_COUNT
];
QHash
<
quint64
,
TabletToolEvent
>
m_tabletTools
;
bool
m_enabled
;
...
...
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