Changeset View
Changeset View
Standalone View
Standalone View
kstyle/breezeshadowhelper.cpp
Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Line(s) | 160 | { | |||
---|---|---|---|---|---|
166 | for( QMap<QWidget*,WId>::const_iterator iter = _widgets.constBegin(); iter != _widgets.constEnd(); ++iter ) | 166 | for( QMap<QWidget*,WId>::const_iterator iter = _widgets.constBegin(); iter != _widgets.constEnd(); ++iter ) | ||
167 | { installShadows( iter.key() ); } | 167 | { installShadows( iter.key() ); } | ||
168 | 168 | | |||
169 | } | 169 | } | ||
170 | 170 | | |||
171 | //_______________________________________________________ | 171 | //_______________________________________________________ | ||
172 | bool ShadowHelper::eventFilter( QObject* object, QEvent* event ) | 172 | bool ShadowHelper::eventFilter( QObject* object, QEvent* event ) | ||
173 | { | 173 | { | ||
174 | 174 | if( Helper::isWayland() ) | |||
anthonyfieroni: We make check on every event for what we know what it is, does it better to use polymorphic… | |||||
175 | { | ||||
176 | QWidget* widget( static_cast<QWidget*>( object ) ); | ||||
177 | auto &&iter = _widgetSurfaces.find( widget ); | ||||
we use Expose everywhere else, why not here? It gets called a lot less davidedmundson: we use Expose everywhere else, why not here? It gets called a lot less | |||||
mart: it's a qwidget, doesn't get expose events | |||||
Also, instead of using first "contains" then .value, one should really use an iterator (to avoid parsing the map twice): auto&& iter = _widgets.find( widget ); Something like that. hpereiradacosta: Also, instead of using first "contains" then .value, one should really use an iterator (to… | |||||
178 | if( event->type() == QEvent::Paint && iter == _widgetSurfaces.end() ) | ||||
179 | { | ||||
180 | // install shadows and update winId | ||||
181 | installShadows( widget ); | ||||
182 | } | ||||
183 | else if( event->type() == QEvent::Hide ) | ||||
184 | { | ||||
185 | auto &&iter = _widgetSurfaces.find( widget ); | ||||
davidedmundson: why not just remove the widget from the list? | |||||
186 | if( iter != _widgetSurfaces.end() ) | ||||
187 | { | ||||
188 | delete iter.value(); | ||||
189 | _widgetSurfaces.erase( iter ); | ||||
190 | } | ||||
191 | } | ||||
192 | } | ||||
193 | else if( Helper::isX11() ) | ||||
194 | { | ||||
175 | // check event type | 195 | // check event type | ||
176 | if( event->type() != QEvent::WinIdChange ) return false; | 196 | if( event->type() != QEvent::WinIdChange ) return false; | ||
177 | 197 | | |||
178 | // cast widget | 198 | // cast widget | ||
179 | QWidget* widget( static_cast<QWidget*>( object ) ); | 199 | QWidget* widget( static_cast<QWidget*>( object ) ); | ||
180 | 200 | | |||
181 | // install shadows and update winId | 201 | // install shadows and update winId | ||
182 | if( installShadows( widget ) ) | 202 | if( installShadows( widget ) ) | ||
183 | { _widgets.insert( widget, widget->winId() ); } | 203 | { _widgets.insert( widget, widget->winId() ); } | ||
204 | } | ||||
184 | 205 | | |||
185 | return false; | 206 | return false; | ||
186 | 207 | | |||
187 | } | 208 | } | ||
188 | 209 | | |||
189 | //_______________________________________________________ | 210 | //_______________________________________________________ | ||
190 | TileSet ShadowHelper::shadowTiles( void ) | 211 | TileSet ShadowHelper::shadowTiles( void ) | ||
191 | { | 212 | { | ||
▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Line(s) | 460 | { | |||
440 | #if BREEZE_HAVE_KWAYLAND | 461 | #if BREEZE_HAVE_KWAYLAND | ||
441 | if( widget->windowHandle()->parent() ) return false; | 462 | if( widget->windowHandle()->parent() ) return false; | ||
442 | if( !_shadowManager || !_shmPool ) return false; | 463 | if( !_shadowManager || !_shmPool ) return false; | ||
443 | 464 | | |||
444 | if( !_shadowTiles.isValid() ) return false; | 465 | if( !_shadowTiles.isValid() ) return false; | ||
445 | 466 | | |||
446 | // create shadow | 467 | // create shadow | ||
447 | using namespace KWayland::Client; | 468 | using namespace KWayland::Client; | ||
448 | auto s = Surface::fromWindow( widget->windowHandle() ); | 469 | auto s = Surface::fromWindow( widget->windowHandle() ); | ||
davidedmundson: this is currently leaking?
fromWindow constructs a new QObject | |||||
it should index those by widget as well i guess, then using this to keep track as opposed to repurposing the _widgets map mart: it should index those by widget as well i guess, then using this to keep track as opposed to… | |||||
449 | if( !s ) return false; | 470 | if( !s ) return false; | ||
450 | 471 | | |||
451 | auto shadow = _shadowManager->createShadow( s, widget ); | 472 | auto shadow = _shadowManager->createShadow( s, widget ); | ||
this is going to be effectively leaking. on a show/hide/show we'll get now have two of these in memory, just one not attached to anything. davidedmundson: this is going to be effectively leaking. on a show/hide/show we'll get now have two of these in… | |||||
452 | if( !shadow->isValid() ) return false; | 473 | if( !shadow->isValid() ) return false; | ||
453 | 474 | | |||
454 | // add the shadow elements | 475 | // add the shadow elements | ||
455 | shadow->attachTop( _shmPool->createBuffer( _shadowTiles.pixmap( 1 ).toImage() ) ); | 476 | shadow->attachTop( _shmPool->createBuffer( _shadowTiles.pixmap( 1 ).toImage() ) ); | ||
456 | shadow->attachTopRight( _shmPool->createBuffer( _shadowTiles.pixmap( 2 ).toImage() ) ); | 477 | shadow->attachTopRight( _shmPool->createBuffer( _shadowTiles.pixmap( 2 ).toImage() ) ); | ||
457 | shadow->attachRight( _shmPool->createBuffer( _shadowTiles.pixmap( 5 ).toImage() ) ); | 478 | shadow->attachRight( _shmPool->createBuffer( _shadowTiles.pixmap( 5 ).toImage() ) ); | ||
458 | shadow->attachBottomRight( _shmPool->createBuffer( _shadowTiles.pixmap( 8 ).toImage() ) ); | 479 | shadow->attachBottomRight( _shmPool->createBuffer( _shadowTiles.pixmap( 8 ).toImage() ) ); | ||
459 | shadow->attachBottom( _shmPool->createBuffer( _shadowTiles.pixmap( 7 ).toImage() ) ); | 480 | shadow->attachBottom( _shmPool->createBuffer( _shadowTiles.pixmap( 7 ).toImage() ) ); | ||
460 | shadow->attachBottomLeft( _shmPool->createBuffer( _shadowTiles.pixmap( 6 ).toImage() ) ); | 481 | shadow->attachBottomLeft( _shmPool->createBuffer( _shadowTiles.pixmap( 6 ).toImage() ) ); | ||
461 | shadow->attachLeft( _shmPool->createBuffer( _shadowTiles.pixmap( 3 ).toImage() ) ); | 482 | shadow->attachLeft( _shmPool->createBuffer( _shadowTiles.pixmap( 3 ).toImage() ) ); | ||
462 | shadow->attachTopLeft( _shmPool->createBuffer( _shadowTiles.pixmap( 0 ).toImage() ) ); | 483 | shadow->attachTopLeft( _shmPool->createBuffer( _shadowTiles.pixmap( 0 ).toImage() ) ); | ||
463 | 484 | | |||
464 | shadow->setOffsets( shadowMargins( widget ) ); | 485 | shadow->setOffsets( shadowMargins( widget ) ); | ||
465 | shadow->commit(); | 486 | shadow->commit(); | ||
466 | s->commit( Surface::CommitFlag::None ); | 487 | s->commit( Surface::CommitFlag::None ); | ||
488 | _widgetSurfaces.insert(widget, s); | ||||
off topic, but why do we have a commit on the surface? We haven't changed the surface, just attaced something to it. davidedmundson: off topic, but why do we have a commit on the surface? We haven't changed the surface, just… | |||||
467 | 489 | | |||
468 | return true; | 490 | return true; | ||
469 | #else | 491 | #else | ||
470 | Q_UNUSED( widget ); | 492 | Q_UNUSED( widget ); | ||
471 | #endif | 493 | #endif | ||
472 | 494 | | |||
473 | return false; | 495 | return false; | ||
474 | } | 496 | } | ||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
We make check on every event for what we know what it is, does it better to use polymorphic helper?