KWin
Loading...
Searching...
No Matches
x11window.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#pragma once
12
13// kwin
15#include "utils/xcbutils.h"
16#include "window.h"
17// Qt
18#include <QElapsedTimer>
19#include <QFlags>
20#include <QPixmap>
21#include <QPointer>
22#include <QWindow>
23// X
24#include <xcb/sync.h>
25
26// TODO: Cleanup the order of things in this .h file
27
28class QTimer;
29class KStartupInfoData;
30class KStartupInfoId;
31
32namespace KWin
33{
34
35class KillPrompt;
36
48
54{
55 Q_OBJECT
56
57public:
59 ~X11DecorationRenderer() override;
60
61protected:
62 void render(const QRegion &region) override;
63
64private:
65 void update();
66
67 QTimer *m_scheduleTimer;
68 xcb_gcontext_t m_gc;
69};
70
71class KWIN_EXPORT X11Window : public Window
72{
73 Q_OBJECT
74
75public:
76 explicit X11Window();
77 ~X11Window() override;
78
79 xcb_window_t frameId() const;
80 xcb_window_t window() const;
81 xcb_window_t wrapperId() const;
82 xcb_window_t inputId() const
83 {
84 return m_decoInputExtent;
85 }
86
87 int desktopId() const;
88 QByteArray sessionId() const;
89 xcb_window_t wmClientLeader() const;
90 QString wmCommand();
91
92 QPointF framePosToClientPos(const QPointF &point) const override;
93 QPointF clientPosToFramePos(const QPointF &point) const override;
94 QSizeF frameSizeToClientSize(const QSizeF &size) const override;
95 QSizeF clientSizeToFrameSize(const QSizeF &size) const override;
96 QRectF frameRectToBufferRect(const QRectF &rect) const;
97 QPointF wrapperPos() const;
98 QSizeF implicitSize() const;
99
100 xcb_visualid_t visual() const;
101 int depth() const;
102 bool hasAlpha() const;
103 QRegion opaqueRegion() const;
104 QList<QRectF> shapeRegion() const;
105
106 pid_t pid() const override;
107 QString windowRole() const override;
108
109 bool isTransient() const override;
110 bool groupTransient() const override;
111 QList<Window *> mainWindows() const override; // Call once before loop , is not indirect
112 bool hasTransient(const Window *c, bool indirect) const override;
113 void checkTransient(xcb_window_t w);
114 Window *findModal(bool allow_itself = false) override;
115 const Group *group() const override;
116 Group *group() override;
117 void checkGroup(Group *gr = nullptr, bool force = false);
118 void changeClientLeaderGroup(Group *gr);
119 bool supportsWindowRules() const override;
120 void updateWindowRules(Rules::Types selection) override;
121 void applyWindowRules() override;
122 void updateFullscreenMonitors(NETFullscreenMonitors topology);
123
124 bool hasNETSupport() const;
125
126 QSizeF minSize() const override;
127 QSizeF maxSize() const override;
128 QSizeF basicUnit() const;
129 QPointF inputPos() const
130 {
131 return input_offset;
132 } // Inside of geometry()
133
134 bool windowEvent(xcb_generic_event_t *e);
135 NET::WindowType windowType() const override;
136
137 bool track(xcb_window_t w);
138 bool manage(xcb_window_t w, bool isMapped);
139
140 void releaseWindow(bool on_shutdown = false);
141 bool hasScheduledRelease() const;
142
143 void destroyWindow() override;
144
145 QStringList activities() const override;
146 void doSetOnActivities(const QStringList &newActivitiesList) override;
147 void updateActivities(bool includeTransients) override;
148
149 bool isShadeable() const override;
150 bool isMaximizable() const override;
151 MaximizeMode maximizeMode() const override;
152 void maximize(MaximizeMode mode) override;
153
154 bool isMinimizable() const override;
155 QRectF iconGeometry() const override;
156
157 bool isFullScreenable() const override;
158 void setFullScreen(bool set) override;
159 bool isFullScreen() const override;
160 int fullScreenMode() const
161 {
162 return m_fullscreenMode; // only for session saving
163 }
164
165 bool userNoBorder() const;
166 bool noBorder() const override;
167 void setNoBorder(bool set) override;
168 bool userCanSetNoBorder() const override;
169 void checkNoBorder() override;
170 void checkActivities() override;
171
172 int sessionStackingOrder() const;
173
174 // Auxiliary functions, depend on the windowType
175 bool wantsInput() const override;
176
177 bool isResizable() const override;
178 bool isMovable() const override;
179 bool isMovableAcrossScreens() const override;
180 bool isCloseable() const override;
181
182 bool takeFocus() override;
183
184 void invalidateDecoration() override;
185
186 void detectShape();
187 void updateShape();
188
190 QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &size) override;
191 QRectF resizeWithChecks(const QRectF &geometry, qreal w, qreal h, xcb_gravity_t gravity);
192 QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &s, xcb_gravity_t gravity);
193 QSizeF constrainClientSize(const QSizeF &size, SizeMode mode = SizeModeAny) const override;
194
195 bool providesContextHelp() const override;
196
198 void updateVisibility();
199 bool hiddenPreview() const;
200
201 bool setupCompositing() override;
202 void finishCompositing() override;
203 void setBlockingCompositing(bool block);
204 void blockCompositing();
205 void unblockCompositing();
206
207 QString captionNormal() const override
208 {
209 return cap_normal;
210 }
211 QString captionSuffix() const override
212 {
213 return cap_suffix;
214 }
215
216 using Window::keyPressEvent;
217 void keyPressEvent(uint key_code, xcb_timestamp_t time); // FRAME ??
218 void updateMouseGrab() override;
219 xcb_window_t moveResizeGrabWindow() const;
220
221 QPointF gravityAdjustment(xcb_gravity_t gravity) const;
222 const QPointF calculateGravitation(bool invert) const;
223
224 void NETMoveResize(qreal x_root, qreal y_root, NET::Direction direction, xcb_button_t button);
225 void NETMoveResizeWindow(int flags, qreal x, qreal y, qreal width, qreal height);
226 void GTKShowWindowMenu(qreal x_root, qreal y_root);
227 void restackWindow(xcb_window_t above, int detail, NET::RequestSource source, xcb_timestamp_t timestamp,
228 bool send_event = false);
229
230 void gotPing(xcb_timestamp_t timestamp);
231
232 void updateUserTime(xcb_timestamp_t time = XCB_TIME_CURRENT_TIME);
233 xcb_timestamp_t userTime() const override;
234 bool hasUserTimeSupport() const;
235
237 static void deleteClient(X11Window *c);
238
239 static bool belongToSameApplication(const X11Window *c1, const X11Window *c2, SameApplicationChecks checks = SameApplicationChecks());
240 static bool sameAppWindowRoleMatch(const X11Window *c1, const X11Window *c2, bool active_hack);
241
242 void killWindow() override;
243 void showContextHelp() override;
244 void checkActiveModal();
245
246 StrutRect strutRect(StrutArea area) const override;
247 bool hasStrut() const override;
248
249 bool isClientSideDecorated() const;
250
251 Xcb::StringProperty fetchPreferredColorScheme() const;
252 QString readPreferredColorScheme(Xcb::StringProperty &property) const;
253 QString preferredColorScheme() const override;
254
255 // sets whether the client should be faked as being on all activities (and be shown during session save)
256 void setSessionActivityOverride(bool needed);
257 bool isClient() const override;
258 bool isOutline() const override;
259 bool isUnmanaged() const override;
260
261 void cancelFocusOutTimer();
262
267 void showOnScreenEdge() override;
268
269 Xcb::StringProperty fetchApplicationMenuServiceName() const;
270 void readApplicationMenuServiceName(Xcb::StringProperty &property);
271 void checkApplicationMenuServiceName();
272
273 Xcb::StringProperty fetchApplicationMenuObjectPath() const;
274 void readApplicationMenuObjectPath(Xcb::StringProperty &property);
275 void checkApplicationMenuObjectPath();
276
278 {
279 xcb_sync_counter_t counter;
280 xcb_sync_int64_t value;
281 xcb_sync_alarm_t alarm;
282 xcb_timestamp_t lastTimestamp;
283 QTimer *timeout, *failsafeTimeout;
286 };
288 {
289 return m_syncRequest;
290 }
291 bool wantsSyncCounter() const;
292 void handleSync();
293 void handleSyncTimeout();
294
295 bool allowWindowActivation(xcb_timestamp_t time = -1U, bool focus_in = false);
296
297 static void cleanupX11();
298
299 quint64 surfaceSerial() const;
300 quint32 pendingSurfaceId() const;
301
302public Q_SLOTS:
303 void closeWindow() override;
304 void updateCaption() override;
305
306private:
307 // Handlers for X11 events
308 bool mapRequestEvent(xcb_map_request_event_t *e);
309 void unmapNotifyEvent(xcb_unmap_notify_event_t *e);
310 void destroyNotifyEvent(xcb_destroy_notify_event_t *e);
311 void configureNotifyEvent(xcb_configure_notify_event_t *e);
312 void configureRequestEvent(xcb_configure_request_event_t *e);
313 void propertyNotifyEvent(xcb_property_notify_event_t *e);
314 void clientMessageEvent(xcb_client_message_event_t *e);
315 void enterNotifyEvent(xcb_enter_notify_event_t *e);
316 void leaveNotifyEvent(xcb_leave_notify_event_t *e);
317 void focusInEvent(xcb_focus_in_event_t *e);
318 void focusOutEvent(xcb_focus_out_event_t *e);
319 void damageNotifyEvent();
320
321 bool buttonPressEvent(xcb_window_t w, int button, int state, int x, int y, int x_root, int y_root, xcb_timestamp_t time = XCB_CURRENT_TIME);
322 bool buttonReleaseEvent(xcb_window_t w, int button, int state, int x, int y, int x_root, int y_root);
323 bool motionNotifyEvent(xcb_window_t w, int state, int x, int y, int x_root, int y_root);
324
325protected:
326 bool belongsToSameApplication(const Window *other, SameApplicationChecks checks) const override;
327 void doSetActive() override;
328 void doSetKeepAbove() override;
329 void doSetKeepBelow() override;
330 void doSetShade(ShadeMode previousShadeMode) override;
331 void doSetDesktop() override;
332 void doMinimize() override;
333 void doSetSkipPager() override;
334 void doSetSkipTaskbar() override;
335 void doSetSkipSwitcher() override;
336 void doSetDemandsAttention() override;
337 void doSetHidden() override;
338 void doSetHiddenByShowDesktop() override;
339 bool belongsToDesktop() const override;
340 bool doStartInteractiveMoveResize() override;
341 bool isWaitingForInteractiveMoveResizeSync() const override;
342 void doInteractiveResizeSync(const QRectF &rect) override;
343 QSizeF resizeIncrements() const override;
344 bool acceptsFocus() const override;
345 void moveResizeInternal(const QRectF &rect, MoveResizeMode mode) override;
346 std::unique_ptr<WindowItem> createItem(Scene *scene) override;
347
348Q_SIGNALS:
350
351private:
352 void exportMappingState(int s); // ICCCM 4.1.3.1, 4.1.4, NETWM 2.5.1
353 bool isManaged() const;
354 void updateAllowedActions(bool force = false);
355 QRect fullscreenMonitorsArea(NETFullscreenMonitors topology) const;
356 void getResourceClass();
357 void getWmNormalHints();
358 void getWmClientMachine();
359 void getMotifHints();
360 void getIcons();
361 void getWmOpaqueRegion();
362 void discardShapeRegion();
363 void fetchName();
364 void fetchIconicName();
365 QString readName() const;
366 void setCaption(const QString &s, bool force = false);
367 bool hasTransientInternal(const X11Window *c, bool indirect, QList<const X11Window *> &set) const;
368 void setShortcutInternal() override;
369 Xcb::Property fetchWmClientLeader() const;
370 void readWmClientLeader(Xcb::Property &p);
371 void getWmClientLeader();
372 Xcb::Property fetchSkipCloseAnimation() const;
373 void readSkipCloseAnimation(Xcb::Property &prop);
374 void getSkipCloseAnimation();
375
376 void configureRequest(int value_mask, qreal rx, qreal ry, qreal rw, qreal rh, int gravity, bool from_tool);
377 NETExtendedStrut strut() const;
378 int checkShadeGeometry(int w, int h);
379 void getSyncCounter();
380 void sendSyncRequest();
381 void leaveInteractiveMoveResize() override;
382 void performInteractiveResize();
383 void establishCommandWindowGrab(uint8_t button);
384 void establishCommandAllGrab(uint8_t button);
385 void resizeDecoration();
386
387 void pingWindow();
388 void killProcess(bool ask, xcb_timestamp_t timestamp = XCB_TIME_CURRENT_TIME);
389 void updateUrgency();
390 static void sendClientMessage(xcb_window_t w, xcb_atom_t a, xcb_atom_t protocol,
391 uint32_t data1 = 0, uint32_t data2 = 0, uint32_t data3 = 0);
392
393 void embedClient(xcb_window_t w, xcb_visualid_t visualid, xcb_colormap_t colormap, uint8_t depth);
394 void detectNoBorder();
395 void updateFrameExtents();
396 void setClientFrameExtents(const NETStrut &strut);
397
398 void internalShow();
399 void internalHide();
400 void internalKeep();
401 void map();
402 void unmap();
403 void updateHiddenPreview();
404
405 void updateInputShape();
406 void updateServerGeometry();
407 void discardWindowPixmap();
408 void updateWindowPixmap();
409
410 xcb_timestamp_t readUserTimeMapTimestamp(const KStartupInfoId *asn_id, const KStartupInfoData *asn_data,
411 bool session) const;
412 xcb_timestamp_t readUserCreationTime() const;
413 void startupIdChanged();
414
415 void updateInputWindow();
416
417 Xcb::Property fetchShowOnScreenEdge() const;
418 void readShowOnScreenEdge(Xcb::Property &property);
423 void updateShowOnScreenEdge();
424
425 void maybeCreateX11DecorationRenderer();
426 void maybeDestroyX11DecorationRenderer();
427 void updateDecoration(bool check_workspace_pos, bool force = false);
428 void createDecoration();
429 void destroyDecoration();
430
431 QWindow *findInternalWindow() const;
432 void checkOutput();
433 void associate();
434 void handleXwaylandScaleChanged();
435
436 Xcb::Window m_client;
437 Xcb::Window m_wrapper;
438 Xcb::Window m_frame;
439 xcb_window_t m_wmClientLeader = XCB_WINDOW_NONE;
440 int m_activityUpdatesBlocked;
441 bool m_blockedActivityUpdatesRequireTransients;
442 Xcb::Window m_moveResizeGrabWindow;
443 bool move_resize_has_keyboard_grab;
444 bool m_managed;
445
446 Xcb::GeometryHints m_geometryHints;
447 void sendSyntheticConfigureNotify();
448 enum MappingState {
449 Withdrawn,
450 Mapped,
451 Unmapped,
452 Kept
453 };
454 MappingState mapping_state;
455
456 Xcb::TransientFor fetchTransient() const;
457 void readTransientProperty(Xcb::TransientFor &transientFor);
458 void readTransient();
459 xcb_window_t verifyTransientFor(xcb_window_t transient_for, bool set);
460 void addTransient(Window *cl) override;
461 void removeFromMainClients();
462 void cleanGrouping();
463 void checkGroupTransients();
464 void setTransient(xcb_window_t new_transient_for_id);
465
466 NETWinInfo *info = nullptr;
467 xcb_window_t m_transientForId;
468 xcb_window_t m_originalTransientForId;
469 X11Window *shade_below;
470 Xcb::MotifHints m_motif;
471 uint noborder : 1;
472 uint app_noborder : 1;
473 uint ignore_focus_stealing : 1;
474 bool blocks_compositing;
475 bool is_shape = false;
476
477 enum FullScreenMode {
478 FullScreenNone,
479 FullScreenNormal
480 } m_fullscreenMode;
481
482 MaximizeMode max_mode;
483 QString cap_normal, cap_iconic, cap_suffix;
484 Group *in_group;
485 QTimer *ping_timer;
486 std::unique_ptr<KillPrompt> m_killPrompt;
487 xcb_timestamp_t m_pingTimestamp;
488 xcb_timestamp_t m_userTime;
489 NET::Actions allowed_actions;
490 bool shade_geometry_change;
491 SyncRequest m_syncRequest;
492 static bool check_active_modal;
493 int sm_stacking_order;
494 xcb_visualid_t m_visual = XCB_NONE;
495 int bit_depth = 24;
496 QRegion opaque_region;
497 mutable QList<QRectF> m_shapeRegion;
498 mutable bool m_shapeRegionIsValid = false;
499 friend struct ResetupRulesProcedure;
500
502
503 Xcb::StringProperty fetchActivities() const;
504 void readActivities(Xcb::StringProperty &property);
505 bool activitiesDefined; // whether the x property was actually set
506
507 bool sessionActivityOverride;
508
509 Xcb::Window m_decoInputExtent;
510 QPointF input_offset;
511
512 QTimer *m_focusOutTimer;
513 QTimer m_releaseTimer;
514
515 QMetaObject::Connection m_edgeGeometryTrackingConnection;
516
517 QMarginsF m_clientFrameExtents;
518 Output *m_lastOutput = nullptr;
519 QRectF m_lastBufferGeometry;
520 QRectF m_lastFrameGeometry;
521 QRectF m_lastClientGeometry;
522 std::unique_ptr<X11DecorationRenderer> m_decorationRenderer;
523
524 bool m_unmanaged = false;
525 bool m_outline = false;
526 quint32 m_pendingSurfaceId = 0;
527 quint64 m_surfaceSerial = 0;
528};
529
530inline xcb_visualid_t X11Window::visual() const
531{
532 return m_visual;
533}
534
535inline int X11Window::depth() const
536{
537 return bit_depth;
538}
539
540inline bool X11Window::hasAlpha() const
541{
542 return depth() == 32;
543}
544
545inline QRegion X11Window::opaqueRegion() const
546{
547 return opaque_region;
548}
549
551{
552 return !m_clientFrameExtents.isNull();
553}
554
555inline bool X11Window::groupTransient() const
556{
557 return m_transientForId == kwinApp()->x11RootWindow();
558}
559
560inline bool X11Window::isTransient() const
561{
562 return m_transientForId != XCB_WINDOW_NONE;
563}
564
565inline const Group *X11Window::group() const
566{
567 return in_group;
568}
569
571{
572 return in_group;
573}
574
576{
577 return max_mode;
578}
579
580inline bool X11Window::isFullScreen() const
581{
582 return m_fullscreenMode != FullScreenNone;
583}
584
585inline bool X11Window::hasNETSupport() const
586{
587 return info->hasNETSupport();
588}
589
591{
592 return sm_stacking_order;
593}
594
595inline bool X11Window::isManaged() const
596{
597 return m_managed;
598}
599
600inline QRectF X11Window::resizeWithChecks(const QRectF &geometry, const QSizeF &s)
601{
602 return resizeWithChecks(geometry, s.width(), s.height(), XCB_GRAVITY_BIT_FORGET);
603}
604
605inline QRectF X11Window::resizeWithChecks(const QRectF &geometry, const QSizeF &s, xcb_gravity_t gravity)
606{
607 return resizeWithChecks(geometry, s.width(), s.height(), gravity);
608}
609
611{
612 return info->userTime() != -1U;
613}
614
615inline xcb_window_t X11Window::moveResizeGrabWindow() const
616{
617 return m_moveResizeGrabWindow;
618}
619
620inline bool X11Window::hiddenPreview() const
621{
622 return mapping_state == Kept;
623}
624
625inline quint64 X11Window::surfaceSerial() const
626{
627 return m_surfaceSerial;
628}
629
630inline quint32 X11Window::pendingSurfaceId() const
631{
632 return m_pendingSurfaceId;
633}
634
635} // namespace
637Q_DECLARE_METATYPE(QList<KWin::X11Window *>)
Decoration::DecoratedClientImpl * client() const
Gravity gravity
Definition window.h:1808
void render(const QRegion &region) override
X11DecorationRenderer(Decoration::DecoratedClientImpl *client)
bool hiddenPreview() const
Window is mapped in order to get a window pixmap.
Definition x11window.h:620
xcb_window_t inputId() const
Definition x11window.h:82
xcb_window_t moveResizeGrabWindow() const
Definition x11window.h:615
bool hasUserTimeSupport() const
Definition x11window.h:610
bool isTransient() const override
Definition x11window.h:560
bool hasAlpha() const
Definition x11window.h:540
int sessionStackingOrder() const
Definition x11window.h:590
xcb_visualid_t visual() const
Definition x11window.h:530
const SyncRequest & syncRequest() const
Definition x11window.h:287
quint32 pendingSurfaceId() const
Definition x11window.h:630
QPointF inputPos() const
Definition x11window.h:129
QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &size) override
resizeWithChecks() resizes according to gravity, and checks workarea position
Definition x11window.h:600
friend bool performTransiencyCheck()
QString captionNormal() const override
Definition x11window.h:207
bool isClientSideDecorated() const
Definition x11window.h:550
QString captionSuffix() const override
Definition x11window.h:211
int depth() const
Definition x11window.h:535
MaximizeMode maximizeMode() const override
Definition x11window.h:575
const Group * group() const override
Definition x11window.h:565
quint64 surfaceSerial() const
Definition x11window.h:625
bool hasNETSupport() const
Definition x11window.h:585
int fullScreenMode() const
Definition x11window.h:160
bool isFullScreen() const override
Definition x11window.h:580
QRegion opaqueRegion() const
Definition x11window.h:545
bool groupTransient() const override
Definition x11window.h:555
Q_DECLARE_METATYPE(KWin::SwitchEvent::State)
ShadeMode
Definition common.h:62
MaximizeMode
Definition common.h:74
StrutArea
Definition common.h:35
Predicate
Defines Predicates on how to search for a Client.
Definition x11window.h:42
xcb_sync_counter_t counter
Definition x11window.h:279
xcb_timestamp_t lastTimestamp
Definition x11window.h:282