@@ -98,6 +98,26 @@ XPanelWindow::XPanelWindow(QObject* parent): ProxyWindowBase(parent) {
98
98
this ,
99
99
&XPanelWindow::xInit
100
100
);
101
+
102
+ this ->bcExclusiveZone .setBinding ([this ]() -> qint32 {
103
+ switch (this ->bExclusionMode .value ()) {
104
+ case ExclusionMode::Ignore: return 0 ;
105
+ case ExclusionMode::Normal: return this ->bExclusiveZone ;
106
+ case ExclusionMode::Auto:
107
+ auto edge = this ->bcExclusionEdge .value ();
108
+ auto margins = this ->bMargins .value ();
109
+
110
+ if (edge == Qt::TopEdge || edge == Qt::BottomEdge) {
111
+ return this ->bImplicitHeight + margins.top + margins.bottom ;
112
+ } else if (edge == Qt::LeftEdge || edge == Qt::RightEdge) {
113
+ return this ->bImplicitWidth + margins.left + margins.right ;
114
+ } else {
115
+ return 0 ;
116
+ }
117
+ }
118
+ });
119
+
120
+ this ->bcExclusionEdge .setBinding ([this ] { return this ->bAnchors .value ().exclusionEdge (); });
101
121
}
102
122
103
123
XPanelWindow::~XPanelWindow () { XPanelStack::instance ()->removePanel (this ); }
@@ -133,15 +153,15 @@ void XPanelWindow::connectWindow() {
133
153
134
154
void XPanelWindow::trySetWidth (qint32 implicitWidth) {
135
155
// only update the actual size if not blocked by anchors
136
- if (!this ->mAnchors .horizontalConstraint ()) {
156
+ if (!this ->bAnchors . value () .horizontalConstraint ()) {
137
157
this ->ProxyWindowBase ::trySetWidth (implicitWidth);
138
158
this ->updateDimensions ();
139
159
}
140
160
}
141
161
142
162
void XPanelWindow::trySetHeight (qint32 implicitHeight) {
143
163
// only update the actual size if not blocked by anchors
144
- if (!this ->mAnchors .verticalConstraint ()) {
164
+ if (!this ->bAnchors . value () .verticalConstraint ()) {
145
165
this ->ProxyWindowBase ::trySetHeight (implicitHeight);
146
166
this ->updateDimensions ();
147
167
}
@@ -152,61 +172,6 @@ void XPanelWindow::setScreen(QuickshellScreenInfo* screen) {
152
172
this ->connectScreen ();
153
173
}
154
174
155
- Anchors XPanelWindow::anchors () const { return this ->mAnchors ; }
156
-
157
- void XPanelWindow::setAnchors (Anchors anchors) {
158
- if (this ->mAnchors == anchors) return ;
159
- this ->mAnchors = anchors;
160
- this ->updateDimensions ();
161
- emit this ->anchorsChanged ();
162
- }
163
-
164
- qint32 XPanelWindow::exclusiveZone () const { return this ->mExclusiveZone ; }
165
-
166
- void XPanelWindow::setExclusiveZone (qint32 exclusiveZone) {
167
- if (this ->mExclusiveZone == exclusiveZone) return ;
168
- this ->mExclusiveZone = exclusiveZone;
169
- this ->setExclusionMode (ExclusionMode::Normal);
170
- this ->updateStrut ();
171
- emit this ->exclusiveZoneChanged ();
172
- }
173
-
174
- ExclusionMode::Enum XPanelWindow::exclusionMode () const { return this ->mExclusionMode ; }
175
-
176
- void XPanelWindow::setExclusionMode (ExclusionMode::Enum exclusionMode) {
177
- if (this ->mExclusionMode == exclusionMode) return ;
178
- this ->mExclusionMode = exclusionMode;
179
- this ->updateStrut ();
180
- emit this ->exclusionModeChanged ();
181
- }
182
-
183
- Margins XPanelWindow::margins () const { return this ->mMargins ; }
184
-
185
- void XPanelWindow::setMargins (Margins margins) {
186
- if (this ->mMargins == margins) return ;
187
- this ->mMargins = margins;
188
- this ->updateDimensions ();
189
- emit this ->marginsChanged ();
190
- }
191
-
192
- bool XPanelWindow::aboveWindows () const { return this ->mAboveWindows ; }
193
-
194
- void XPanelWindow::setAboveWindows (bool aboveWindows) {
195
- if (this ->mAboveWindows == aboveWindows) return ;
196
- this ->mAboveWindows = aboveWindows;
197
- this ->updateAboveWindows ();
198
- emit this ->aboveWindowsChanged ();
199
- }
200
-
201
- bool XPanelWindow::focusable () const { return this ->mFocusable ; }
202
-
203
- void XPanelWindow::setFocusable (bool focusable) {
204
- if (this ->mFocusable == focusable) return ;
205
- this ->mFocusable = focusable;
206
- this ->updateFocusable ();
207
- emit this ->focusableChanged ();
208
- }
209
-
210
175
void XPanelWindow::xInit () {
211
176
if (this ->window == nullptr || this ->window ->handle () == nullptr ) return ;
212
177
this ->updateDimensions ();
@@ -271,44 +236,42 @@ void XPanelWindow::updateDimensions(bool propagate) {
271
236
272
237
auto screenGeometry = this ->mScreen ->geometry ();
273
238
274
- if (this ->mExclusionMode != ExclusionMode::Ignore) {
239
+ if (this ->bExclusionMode != ExclusionMode::Ignore) {
275
240
for (auto * panel: XPanelStack::instance ()->panels (this )) {
276
241
// we only care about windows below us
277
242
if (panel == this ) break ;
278
243
279
244
// we only care about windows in the same layer
280
- if (panel->mAboveWindows != this ->mAboveWindows ) continue ;
245
+ if (panel->bAboveWindows != this ->bAboveWindows ) continue ;
281
246
282
247
if (panel->mScreen != this ->mScreen ) continue ;
283
248
284
- int side = -1 ;
285
- quint32 exclusiveZone = 0 ;
286
- panel->getExclusion (side, exclusiveZone);
287
-
288
- if (exclusiveZone == 0 ) continue ;
289
-
290
- auto zone = static_cast <qint32>(exclusiveZone);
249
+ auto edge = this ->bcExclusionEdge .value ();
250
+ auto exclusiveZone = this ->bcExclusiveZone .value ();
291
251
292
252
screenGeometry.adjust (
293
- side == 0 ? zone : 0 ,
294
- side == 2 ? zone : 0 ,
295
- side == 1 ? -zone : 0 ,
296
- side == 3 ? -zone : 0
253
+ edge == Qt::LeftEdge ? exclusiveZone : 0 ,
254
+ edge == Qt::TopEdge ? exclusiveZone : 0 ,
255
+ edge == Qt::RightEdge ? -exclusiveZone : 0 ,
256
+ edge == Qt::BottomEdge ? -exclusiveZone : 0
297
257
);
298
258
}
299
259
}
300
260
301
261
auto geometry = QRect ();
302
262
303
- if (this ->mAnchors .horizontalConstraint ()) {
304
- geometry.setX (screenGeometry.x () + this ->mMargins .left );
305
- geometry.setWidth (screenGeometry.width () - this ->mMargins .left - this ->mMargins .right );
263
+ auto anchors = this ->bAnchors .value ();
264
+ auto margins = this ->bMargins .value ();
265
+
266
+ if (anchors.horizontalConstraint ()) {
267
+ geometry.setX (screenGeometry.x () + margins.left );
268
+ geometry.setWidth (screenGeometry.width () - margins.left - margins.right );
306
269
} else {
307
- if (this -> mAnchors .mLeft ) {
308
- geometry.setX (screenGeometry.x () + this -> mMargins .left );
309
- } else if (this -> mAnchors .mRight ) {
270
+ if (anchors .mLeft ) {
271
+ geometry.setX (screenGeometry.x () + margins .left );
272
+ } else if (anchors .mRight ) {
310
273
geometry.setX (
311
- screenGeometry.x () + screenGeometry.width () - this ->implicitWidth () - this -> mMargins .right
274
+ screenGeometry.x () + screenGeometry.width () - this ->implicitWidth () - margins .right
312
275
);
313
276
} else {
314
277
geometry.setX (screenGeometry.x () + screenGeometry.width () / 2 - this ->implicitWidth () / 2 );
@@ -317,16 +280,15 @@ void XPanelWindow::updateDimensions(bool propagate) {
317
280
geometry.setWidth (this ->implicitWidth ());
318
281
}
319
282
320
- if (this -> mAnchors .verticalConstraint ()) {
321
- geometry.setY (screenGeometry.y () + this -> mMargins .top );
322
- geometry.setHeight (screenGeometry.height () - this -> mMargins .top - this -> mMargins .bottom );
283
+ if (anchors .verticalConstraint ()) {
284
+ geometry.setY (screenGeometry.y () + margins .top );
285
+ geometry.setHeight (screenGeometry.height () - margins .top - margins .bottom );
323
286
} else {
324
- if (this -> mAnchors .mTop ) {
325
- geometry.setY (screenGeometry.y () + this -> mMargins .top );
326
- } else if (this -> mAnchors .mBottom ) {
287
+ if (anchors .mTop ) {
288
+ geometry.setY (screenGeometry.y () + margins .top );
289
+ } else if (anchors .mBottom ) {
327
290
geometry.setY (
328
- screenGeometry.y () + screenGeometry.height () - this ->implicitHeight ()
329
- - this ->mMargins .bottom
291
+ screenGeometry.y () + screenGeometry.height () - this ->implicitHeight () - margins.bottom
330
292
);
331
293
} else {
332
294
geometry.setY (screenGeometry.y () + screenGeometry.height () / 2 - this ->implicitHeight () / 2 );
@@ -355,42 +317,6 @@ void XPanelWindow::updatePanelStack() {
355
317
}
356
318
}
357
319
358
- void XPanelWindow::getExclusion (int & side, quint32& exclusiveZone) {
359
- if (this ->mExclusionMode == ExclusionMode::Ignore) {
360
- exclusiveZone = 0 ;
361
- return ;
362
- }
363
-
364
- auto & anchors = this ->mAnchors ;
365
- if (anchors.mLeft || anchors.mRight || anchors.mTop || anchors.mBottom ) {
366
- if (!anchors.horizontalConstraint ()
367
- && (anchors.verticalConstraint () || (!anchors.mTop && !anchors.mBottom )))
368
- {
369
- side = anchors.mLeft ? 0 : anchors.mRight ? 1 : -1 ;
370
- } else if (!anchors.verticalConstraint ()
371
- && (anchors.horizontalConstraint () || (!anchors.mLeft && !anchors.mRight )))
372
- {
373
- side = anchors.mTop ? 2 : anchors.mBottom ? 3 : -1 ;
374
- }
375
- }
376
-
377
- if (side == -1 ) return ;
378
-
379
- auto autoExclude = this ->mExclusionMode == ExclusionMode::Auto;
380
-
381
- if (autoExclude) {
382
- if (side == 0 || side == 1 ) {
383
- exclusiveZone =
384
- this ->implicitWidth () + (side == 0 ? this ->mMargins .left : this ->mMargins .right );
385
- } else {
386
- exclusiveZone =
387
- this ->implicitHeight () + (side == 2 ? this ->mMargins .top : this ->mMargins .bottom );
388
- }
389
- } else {
390
- exclusiveZone = this ->mExclusiveZone ;
391
- }
392
- }
393
-
394
320
// Disable xinerama structs to break multi monitor configurations with bad WMs less.
395
321
// Usually this results in one monitor at the top left corner of the root window working
396
322
// perfectly and all others being broken semi randomly.
@@ -400,31 +326,38 @@ void XPanelWindow::updateStrut(bool propagate) {
400
326
if (this ->window == nullptr || this ->window ->handle () == nullptr ) return ;
401
327
auto * conn = x11Connection ();
402
328
403
- int side = -1 ;
404
- quint32 exclusiveZone = 0 ;
405
-
406
- this ->getExclusion (side, exclusiveZone);
329
+ auto edge = this ->bcExclusionEdge .value ();
330
+ auto exclusiveZone = this ->bcExclusiveZone .value ();
407
331
408
- if (side == - 1 || this ->mExclusionMode == ExclusionMode::Ignore) {
332
+ if (edge == 0 || this ->bExclusionMode == ExclusionMode::Ignore) {
409
333
xcb_delete_property (conn, this ->window ->winId (), XAtom::_NET_WM_STRUT.atom ());
410
334
xcb_delete_property (conn, this ->window ->winId (), XAtom::_NET_WM_STRUT_PARTIAL.atom ());
411
335
return ;
412
336
}
413
337
414
338
auto rootGeometry = this ->window ->screen ()->virtualGeometry ();
415
339
auto screenGeometry = this ->window ->screen ()->geometry ();
416
- auto horizontal = side == 0 || side == 1 ;
340
+ auto horizontal = edge == Qt::LeftEdge || edge == Qt::RightEdge ;
417
341
418
342
if (XINERAMA_STRUTS) {
419
- switch (side ) {
420
- case 0 : exclusiveZone += screenGeometry.left (); break ;
421
- case 1 : exclusiveZone += rootGeometry.right () - screenGeometry.right (); break ;
422
- case 2 : exclusiveZone += screenGeometry.top (); break ;
423
- case 3 : exclusiveZone += rootGeometry.bottom () - screenGeometry.bottom (); break ;
343
+ switch (edge ) {
344
+ case Qt::LeftEdge : exclusiveZone += screenGeometry.left (); break ;
345
+ case Qt::RightEdge : exclusiveZone += rootGeometry.right () - screenGeometry.right (); break ;
346
+ case Qt::TopEdge : exclusiveZone += screenGeometry.top (); break ;
347
+ case Qt::BottomEdge : exclusiveZone += rootGeometry.bottom () - screenGeometry.bottom (); break ;
424
348
default : break ;
425
349
}
426
350
}
427
351
352
+ quint32 side = -1 ;
353
+
354
+ switch (edge) {
355
+ case Qt::LeftEdge: side = 0 ; break ;
356
+ case Qt::RightEdge: side = 1 ; break ;
357
+ case Qt::TopEdge: side = 2 ; break ;
358
+ case Qt::BottomEdge: side = 3 ; break ;
359
+ }
360
+
428
361
auto data = std::array<quint32, 12 >();
429
362
data[side] = exclusiveZone;
430
363
@@ -461,13 +394,14 @@ void XPanelWindow::updateStrut(bool propagate) {
461
394
void XPanelWindow::updateAboveWindows () {
462
395
if (this ->window == nullptr ) return ;
463
396
464
- this ->window ->setFlag (Qt::WindowStaysOnBottomHint, !this ->mAboveWindows );
465
- this ->window ->setFlag (Qt::WindowStaysOnTopHint, this ->mAboveWindows );
397
+ auto above = this ->bAboveWindows .value ();
398
+ this ->window ->setFlag (Qt::WindowStaysOnBottomHint, !above);
399
+ this ->window ->setFlag (Qt::WindowStaysOnTopHint, above);
466
400
}
467
401
468
402
void XPanelWindow::updateFocusable () {
469
403
if (this ->window == nullptr ) return ;
470
- this ->window ->setFlag (Qt::WindowDoesNotAcceptFocus, !this ->mFocusable );
404
+ this ->window ->setFlag (Qt::WindowDoesNotAcceptFocus, !this ->bFocusable );
471
405
}
472
406
473
407
// XPanelInterface
0 commit comments