@@ -98,6 +98,26 @@ XPanelWindow::XPanelWindow(QObject* parent): ProxyWindowBase(parent) {
9898 this ,
9999 &XPanelWindow::xInit
100100 );
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 (); });
101121}
102122
103123XPanelWindow::~XPanelWindow () { XPanelStack::instance ()->removePanel (this ); }
@@ -133,15 +153,15 @@ void XPanelWindow::connectWindow() {
133153
134154void XPanelWindow::trySetWidth (qint32 implicitWidth) {
135155 // only update the actual size if not blocked by anchors
136- if (!this ->mAnchors .horizontalConstraint ()) {
156+ if (!this ->bAnchors . value () .horizontalConstraint ()) {
137157 this ->ProxyWindowBase ::trySetWidth (implicitWidth);
138158 this ->updateDimensions ();
139159 }
140160}
141161
142162void XPanelWindow::trySetHeight (qint32 implicitHeight) {
143163 // only update the actual size if not blocked by anchors
144- if (!this ->mAnchors .verticalConstraint ()) {
164+ if (!this ->bAnchors . value () .verticalConstraint ()) {
145165 this ->ProxyWindowBase ::trySetHeight (implicitHeight);
146166 this ->updateDimensions ();
147167 }
@@ -152,61 +172,6 @@ void XPanelWindow::setScreen(QuickshellScreenInfo* screen) {
152172 this ->connectScreen ();
153173}
154174
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-
210175void XPanelWindow::xInit () {
211176 if (this ->window == nullptr || this ->window ->handle () == nullptr ) return ;
212177 this ->updateDimensions ();
@@ -271,44 +236,42 @@ void XPanelWindow::updateDimensions(bool propagate) {
271236
272237 auto screenGeometry = this ->mScreen ->geometry ();
273238
274- if (this ->mExclusionMode != ExclusionMode::Ignore) {
239+ if (this ->bExclusionMode != ExclusionMode::Ignore) {
275240 for (auto * panel: XPanelStack::instance ()->panels (this )) {
276241 // we only care about windows below us
277242 if (panel == this ) break ;
278243
279244 // we only care about windows in the same layer
280- if (panel->mAboveWindows != this ->mAboveWindows ) continue ;
245+ if (panel->bAboveWindows != this ->bAboveWindows ) continue ;
281246
282247 if (panel->mScreen != this ->mScreen ) continue ;
283248
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 ();
291251
292252 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
297257 );
298258 }
299259 }
300260
301261 auto geometry = QRect ();
302262
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 );
306269 } 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 ) {
310273 geometry.setX (
311- screenGeometry.x () + screenGeometry.width () - this ->implicitWidth () - this -> mMargins .right
274+ screenGeometry.x () + screenGeometry.width () - this ->implicitWidth () - margins .right
312275 );
313276 } else {
314277 geometry.setX (screenGeometry.x () + screenGeometry.width () / 2 - this ->implicitWidth () / 2 );
@@ -317,16 +280,15 @@ void XPanelWindow::updateDimensions(bool propagate) {
317280 geometry.setWidth (this ->implicitWidth ());
318281 }
319282
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 );
323286 } 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 ) {
327290 geometry.setY (
328- screenGeometry.y () + screenGeometry.height () - this ->implicitHeight ()
329- - this ->mMargins .bottom
291+ screenGeometry.y () + screenGeometry.height () - this ->implicitHeight () - margins.bottom
330292 );
331293 } else {
332294 geometry.setY (screenGeometry.y () + screenGeometry.height () / 2 - this ->implicitHeight () / 2 );
@@ -355,42 +317,6 @@ void XPanelWindow::updatePanelStack() {
355317 }
356318}
357319
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-
394320// Disable xinerama structs to break multi monitor configurations with bad WMs less.
395321// Usually this results in one monitor at the top left corner of the root window working
396322// perfectly and all others being broken semi randomly.
@@ -400,31 +326,38 @@ void XPanelWindow::updateStrut(bool propagate) {
400326 if (this ->window == nullptr || this ->window ->handle () == nullptr ) return ;
401327 auto * conn = x11Connection ();
402328
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 ();
407331
408- if (side == - 1 || this ->mExclusionMode == ExclusionMode::Ignore) {
332+ if (edge == 0 || this ->bExclusionMode == ExclusionMode::Ignore) {
409333 xcb_delete_property (conn, this ->window ->winId (), XAtom::_NET_WM_STRUT.atom ());
410334 xcb_delete_property (conn, this ->window ->winId (), XAtom::_NET_WM_STRUT_PARTIAL.atom ());
411335 return ;
412336 }
413337
414338 auto rootGeometry = this ->window ->screen ()->virtualGeometry ();
415339 auto screenGeometry = this ->window ->screen ()->geometry ();
416- auto horizontal = side == 0 || side == 1 ;
340+ auto horizontal = edge == Qt::LeftEdge || edge == Qt::RightEdge ;
417341
418342 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 ;
424348 default : break ;
425349 }
426350 }
427351
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+
428361 auto data = std::array<quint32, 12 >();
429362 data[side] = exclusiveZone;
430363
@@ -461,13 +394,14 @@ void XPanelWindow::updateStrut(bool propagate) {
461394void XPanelWindow::updateAboveWindows () {
462395 if (this ->window == nullptr ) return ;
463396
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);
466400}
467401
468402void XPanelWindow::updateFocusable () {
469403 if (this ->window == nullptr ) return ;
470- this ->window ->setFlag (Qt::WindowDoesNotAcceptFocus, !this ->mFocusable );
404+ this ->window ->setFlag (Qt::WindowDoesNotAcceptFocus, !this ->bFocusable );
471405}
472406
473407// XPanelInterface
0 commit comments