| 1 |
#include "lxqttaskbarwlrwm.h" |
| 2 |
#include "lxqtwmbackend_wlr.h" |
| 3 |
#include "workspace.hpp" |
| 4 |
|
| 5 |
#include <QIcon> |
| 6 |
#include <QDateTime> |
| 7 |
#include <QScreen> |
| 8 |
#include <algorithm> |
| 9 |
|
| 10 |
#include <private/qwaylandscreen_p.h> |
| 11 |
|
| 12 |
// Function to erase a window from the vector |
| 13 |
void eraseWindow(std::vector<WId>& windows, WId tgt) { |
| 14 |
// Use std::vector::iterator to find the window |
| 15 |
auto it = std::find(windows.begin(), windows.end(), tgt); |
| 16 |
|
| 17 |
// Check if the window was found |
| 18 |
if (it != windows.end()) { |
| 19 |
// If found, erase the element pointed to by the iterator |
| 20 |
windows.erase(it); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
LXQtTaskbarWlrootsBackend::LXQtTaskbarWlrootsBackend(QObject *parent) : |
| 25 |
ILXQtAbstractWMInterface(parent) |
| 26 |
{ |
| 27 |
m_managment.reset(new LXQtTaskbarWlrootsWindowManagment); |
| 28 |
m_wsmgr.reset(new LXQt::Taskbar::WorkspaceManagerV1); |
| 29 |
|
| 30 |
connect(m_managment.get(), &LXQtTaskbarWlrootsWindowManagment::windowCreated, this, &LXQtTaskbarWlrootsBackend::addWindow); |
| 31 |
|
| 32 |
connect(m_wsmgr.get(), &LXQt::Taskbar::WorkspaceManagerV1::workspaceAdded, this, &LXQtTaskbarWlrootsBackend::workspacesCountChanged); |
| 33 |
connect(m_wsmgr.get(), &LXQt::Taskbar::WorkspaceManagerV1::workspaceRemoved, this, &LXQtTaskbarWlrootsBackend::workspacesCountChanged); |
| 34 |
connect(m_wsmgr.get(), &LXQt::Taskbar::WorkspaceManagerV1::currentWorkspaceChanged, this, [this] (const QList<QScreen*> &screens) |
| 35 |
{ |
| 36 |
for (auto scrn : screens) |
| 37 |
{ |
| 38 |
emit currentWorkspaceChanged(m_wsmgr->currentWorkspaceIndex(scrn), scrn->name()); |
| 39 |
} |
| 40 |
}); |
| 41 |
connect(m_wsmgr.get(), &LXQt::Taskbar::WorkspaceManagerV1::nameChanged, this, [this]() { |
| 42 |
emit workspaceNameChanged(-1); // without specifying an index |
| 43 |
}); |
| 44 |
} |
| 45 |
|
| 46 |
bool LXQtTaskbarWlrootsBackend::supportsAction(WId, LXQtTaskBarBackendAction action) const |
| 47 |
{ |
| 48 |
switch (action) |
| 49 |
{ |
| 50 |
case LXQtTaskBarBackendAction::Maximize: |
| 51 |
return true; |
| 52 |
|
| 53 |
case LXQtTaskBarBackendAction::Minimize: |
| 54 |
return true; |
| 55 |
|
| 56 |
case LXQtTaskBarBackendAction::FullScreen: |
| 57 |
return true; |
| 58 |
|
| 59 |
case LXQtTaskBarBackendAction::DesktopSwitch: |
| 60 |
return true; |
| 61 |
|
| 62 |
default: |
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
return false; |
| 67 |
} |
| 68 |
|
| 69 |
bool LXQtTaskbarWlrootsBackend::reloadWindows() |
| 70 |
{ |
| 71 |
const QVector<WId> wids = getCurrentWindows(); |
| 72 |
|
| 73 |
// Force removal and re-adding |
| 74 |
for(WId windowId : wids) |
| 75 |
{ |
| 76 |
emit windowRemoved(windowId); |
| 77 |
} |
| 78 |
for(WId windowId : wids) |
| 79 |
{ |
| 80 |
emit windowAdded(windowId); |
| 81 |
} |
| 82 |
|
| 83 |
return true; |
| 84 |
} |
| 85 |
|
| 86 |
QVector<WId> LXQtTaskbarWlrootsBackend::getCurrentWindows() const |
| 87 |
{ |
| 88 |
QVector<WId> wids; |
| 89 |
|
| 90 |
for( WId wid: windows ){ |
| 91 |
wids << wid; |
| 92 |
} |
| 93 |
|
| 94 |
return wids; |
| 95 |
} |
| 96 |
|
| 97 |
QString LXQtTaskbarWlrootsBackend::getWindowTitle(WId windowId) const |
| 98 |
{ |
| 99 |
LXQtTaskbarWlrootsWindow *window = getWindow(windowId); |
| 100 |
if(!window) |
| 101 |
return QString(); |
| 102 |
|
| 103 |
return window->windowState.title; |
| 104 |
} |
| 105 |
|
| 106 |
bool LXQtTaskbarWlrootsBackend::applicationDemandsAttention(WId) const |
| 107 |
{ |
| 108 |
return false; |
| 109 |
} |
| 110 |
|
| 111 |
QIcon LXQtTaskbarWlrootsBackend::getApplicationIcon(WId windowId, int devicePixels) const |
| 112 |
{ |
| 113 |
Q_UNUSED(devicePixels) |
| 114 |
|
| 115 |
LXQtTaskbarWlrootsWindow *window = getWindow(windowId); |
| 116 |
if(!window) |
| 117 |
return QIcon(); |
| 118 |
|
| 119 |
return window->icon; |
| 120 |
} |
| 121 |
|
| 122 |
QString LXQtTaskbarWlrootsBackend::getWindowClass(WId windowId) const |
| 123 |
{ |
| 124 |
LXQtTaskbarWlrootsWindow *window = getWindow(windowId); |
| 125 |
if(!window) |
| 126 |
return QString(); |
| 127 |
return window->windowState.appId; |
| 128 |
} |
| 129 |
|
| 130 |
LXQtTaskBarWindowLayer LXQtTaskbarWlrootsBackend::getWindowLayer(WId) const |
| 131 |
{ |
| 132 |
return LXQtTaskBarWindowLayer::Normal; |
| 133 |
} |
| 134 |
|
| 135 |
bool LXQtTaskbarWlrootsBackend::setWindowLayer(WId, LXQtTaskBarWindowLayer) |
| 136 |
{ |
| 137 |
return false; |
| 138 |
} |
| 139 |
|
| 140 |
LXQtTaskBarWindowState LXQtTaskbarWlrootsBackend::getWindowState(WId windowId) const |
| 141 |
{ |
| 142 |
LXQtTaskbarWlrootsWindow *window = getWindow(windowId); |
| 143 |
if(!window) |
| 144 |
return LXQtTaskBarWindowState::Normal; |
| 145 |
|
| 146 |
if(window->windowState.minimized) |
| 147 |
return LXQtTaskBarWindowState::Minimized; |
| 148 |
|
| 149 |
if(window->windowState.maximized) |
| 150 |
return LXQtTaskBarWindowState::Maximized; |
| 151 |
|
| 152 |
if(window->windowState.fullscreen) |
| 153 |
return LXQtTaskBarWindowState::FullScreen; |
| 154 |
|
| 155 |
return LXQtTaskBarWindowState::Normal; |
| 156 |
} |
| 157 |
|
| 158 |
bool LXQtTaskbarWlrootsBackend::setWindowState(WId windowId, LXQtTaskBarWindowState state, bool set) |
| 159 |
{ |
| 160 |
LXQtTaskbarWlrootsWindow *window = getWindow(windowId); |
| 161 |
if(!window) |
| 162 |
return false; |
| 163 |
|
| 164 |
switch (state) |
| 165 |
{ |
| 166 |
case LXQtTaskBarWindowState::Minimized: |
| 167 |
{ |
| 168 |
if ( set ) { |
| 169 |
window->set_minimized(); |
| 170 |
} |
| 171 |
|
| 172 |
else { |
| 173 |
window->unset_minimized(); |
| 174 |
} |
| 175 |
|
| 176 |
break; |
| 177 |
} |
| 178 |
case LXQtTaskBarWindowState::Maximized: |
| 179 |
case LXQtTaskBarWindowState::MaximizedVertically: |
| 180 |
case LXQtTaskBarWindowState::MaximizedHorizontally: |
| 181 |
{ |
| 182 |
if ( set ) { |
| 183 |
window->set_maximized(); |
| 184 |
} |
| 185 |
|
| 186 |
else { |
| 187 |
window->unset_maximized(); |
| 188 |
} |
| 189 |
|
| 190 |
break; |
| 191 |
} |
| 192 |
case LXQtTaskBarWindowState::Normal: |
| 193 |
{ |
| 194 |
if (set) |
| 195 |
{ |
| 196 |
if ( window->windowState.maximized) { |
| 197 |
window->unset_maximized(); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
break; |
| 202 |
} |
| 203 |
|
| 204 |
case LXQtTaskBarWindowState::FullScreen: |
| 205 |
{ |
| 206 |
if ( set ) { |
| 207 |
window->set_fullscreen(nullptr); |
| 208 |
} |
| 209 |
|
| 210 |
else { |
| 211 |
window->unset_fullscreen(); |
| 212 |
} |
| 213 |
break; |
| 214 |
} |
| 215 |
|
| 216 |
default: |
| 217 |
return false; |
| 218 |
} |
| 219 |
|
| 220 |
return true; |
| 221 |
} |
| 222 |
|
| 223 |
bool LXQtTaskbarWlrootsBackend::isWindowActive(WId windowId) const |
| 224 |
{ |
| 225 |
LXQtTaskbarWlrootsWindow *window = getWindow(windowId); |
| 226 |
if(!window) |
| 227 |
return false; |
| 228 |
|
| 229 |
return activeWindow == windowId || window->windowState.activated; |
| 230 |
} |
| 231 |
|
| 232 |
bool LXQtTaskbarWlrootsBackend::raiseWindow(WId windowId, bool onCurrentWorkSpace) |
| 233 |
{ |
| 234 |
Q_UNUSED(onCurrentWorkSpace) // Cannot be done on a generic wlroots-based compositor! |
| 235 |
|
| 236 |
LXQtTaskbarWlrootsWindow *window = getWindow(windowId); |
| 237 |
if(!window) |
| 238 |
return false; |
| 239 |
|
| 240 |
window->activate(); |
| 241 |
return true; |
| 242 |
} |
| 243 |
|
| 244 |
bool LXQtTaskbarWlrootsBackend::closeWindow(WId windowId) |
| 245 |
{ |
| 246 |
LXQtTaskbarWlrootsWindow *window = getWindow(windowId); |
| 247 |
if(!window) |
| 248 |
return false; |
| 249 |
|
| 250 |
window->close(); |
| 251 |
return true; |
| 252 |
} |
| 253 |
|
| 254 |
WId LXQtTaskbarWlrootsBackend::getActiveWindow() const |
| 255 |
{ |
| 256 |
return activeWindow; |
| 257 |
} |
| 258 |
|
| 259 |
int LXQtTaskbarWlrootsBackend::getWorkspacesCount(QScreen *screen) const |
| 260 |
{ |
| 261 |
return m_wsmgr->workspaceCount(screen); |
| 262 |
} |
| 263 |
|
| 264 |
QString LXQtTaskbarWlrootsBackend::getWorkspaceName(int idx, QString sceenName) const |
| 265 |
{ |
| 266 |
return m_wsmgr->workspaceName(idx, sceenName); |
| 267 |
} |
| 268 |
|
| 269 |
int LXQtTaskbarWlrootsBackend::getCurrentWorkspace(QScreen *screen) const |
| 270 |
{ |
| 271 |
return m_wsmgr->currentWorkspaceIndex(screen); |
| 272 |
} |
| 273 |
|
| 274 |
bool LXQtTaskbarWlrootsBackend::setCurrentWorkspace(int idx, QScreen *screen) |
| 275 |
{ |
| 276 |
m_wsmgr->setCurrentWorkspaceIndex(idx, screen); |
| 277 |
m_wsmgr->commit(); |
| 278 |
|
| 279 |
/** Currently we always assume that this is true */ |
| 280 |
return true; |
| 281 |
} |
| 282 |
|
| 283 |
int LXQtTaskbarWlrootsBackend::getWindowWorkspace(WId) const |
| 284 |
{ |
| 285 |
// Until this works, get the current workspace to not affect the taskbar |
| 286 |
return getCurrentWorkspace(); |
| 287 |
} |
| 288 |
|
| 289 |
bool LXQtTaskbarWlrootsBackend::setWindowOnWorkspace(WId, int) |
| 290 |
{ |
| 291 |
return true; |
| 292 |
} |
| 293 |
|
| 294 |
void LXQtTaskbarWlrootsBackend::moveApplicationToPrevNextMonitor(WId, bool, bool) |
| 295 |
{ |
| 296 |
} |
| 297 |
|
| 298 |
bool LXQtTaskbarWlrootsBackend::isWindowOnScreen(QScreen *screen, WId windowId) const |
| 299 |
{ |
| 300 |
LXQtTaskbarWlrootsWindow *window = getWindow(windowId); |
| 301 |
if(window) |
| 302 |
{ |
| 303 |
QtWaylandClient::QWaylandScreen *waylandScreen = dynamic_cast<QtWaylandClient::QWaylandScreen*>(screen->handle()); |
| 304 |
if (waylandScreen) |
| 305 |
{ |
| 306 |
wl_output *output = waylandScreen->output(); |
| 307 |
return window->windowState.outputs.contains(output); |
| 308 |
} |
| 309 |
} |
| 310 |
return false; |
| 311 |
} |
| 312 |
|
| 313 |
bool LXQtTaskbarWlrootsBackend::setDesktopLayout(Qt::Orientation, int, int, bool) { |
| 314 |
// Wlroots has no support for workspace as of 2024-August-20 |
| 315 |
return false; |
| 316 |
} |
| 317 |
|
| 318 |
void LXQtTaskbarWlrootsBackend::moveApplication(WId) |
| 319 |
{ |
| 320 |
} |
| 321 |
|
| 322 |
void LXQtTaskbarWlrootsBackend::resizeApplication(WId) |
| 323 |
{ |
| 324 |
} |
| 325 |
|
| 326 |
void LXQtTaskbarWlrootsBackend::refreshIconGeometry(WId, const QRect &) |
| 327 |
{ |
| 328 |
|
| 329 |
} |
| 330 |
|
| 331 |
bool LXQtTaskbarWlrootsBackend::isAreaOverlapped(const QRect &) const |
| 332 |
{ |
| 333 |
return false; |
| 334 |
} |
| 335 |
|
| 336 |
bool LXQtTaskbarWlrootsBackend::isShowingDesktop() const |
| 337 |
{ |
| 338 |
return m_managment->isShowingDesktop(); |
| 339 |
} |
| 340 |
|
| 341 |
bool LXQtTaskbarWlrootsBackend::showDesktop(bool value) |
| 342 |
{ |
| 343 |
if (isShowingDesktop() == value) |
| 344 |
return false; |
| 345 |
|
| 346 |
// If the windows are going to be restored but all of them are already restored, |
| 347 |
// removed or closed (e.g., by the user), show the desktop instead. |
| 348 |
if (!value) |
| 349 |
{ |
| 350 |
bool hasMinimized = false; |
| 351 |
for (auto windowId : std::as_const(showDesktopWins)) |
| 352 |
{ |
| 353 |
if (getWindowState(windowId) == LXQtTaskBarWindowState::Minimized |
| 354 |
&& std::find(windows.begin(), windows.end(), windowId) != windows.end()) |
| 355 |
{ |
| 356 |
hasMinimized = true; |
| 357 |
break; |
| 358 |
} |
| 359 |
} |
| 360 |
if (!hasMinimized) |
| 361 |
value = true; |
| 362 |
} |
| 363 |
|
| 364 |
if (value) |
| 365 |
{ |
| 366 |
showDesktopWins.clear(); |
| 367 |
QVector<WId> wids = getCurrentWindows(); |
| 368 |
std::sort(wids.begin(), wids.end(), [this](WId id1, WId id2) { |
| 369 |
// sort the list by activation time to keep the z-order on restoring |
| 370 |
return (lastActivated.value(id1) < lastActivated.value(id2)); |
| 371 |
}); |
| 372 |
for (auto windowId : std::as_const(wids)) |
| 373 |
{ |
| 374 |
if (getWindowState(windowId) == LXQtTaskBarWindowState::Minimized) |
| 375 |
{ // was minimized before showing the desktop and so, should not be restored later |
| 376 |
continue; |
| 377 |
} |
| 378 |
setWindowState(windowId, LXQtTaskBarWindowState::Minimized, true); |
| 379 |
showDesktopWins.push_back(windowId); |
| 380 |
} |
| 381 |
} |
| 382 |
else |
| 383 |
{ |
| 384 |
for (auto windowId : std::as_const(showDesktopWins)) |
| 385 |
setWindowState(windowId, LXQtTaskBarWindowState::Minimized, false); |
| 386 |
showDesktopWins.clear(); |
| 387 |
} |
| 388 |
m_managment->setShowingDesktop(!showDesktopWins.empty()); |
| 389 |
return true; |
| 390 |
} |
| 391 |
|
| 392 |
WId LXQtTaskbarWlrootsBackend::findWindow(WId tgt) const |
| 393 |
{ |
| 394 |
for (auto id : std::as_const(windows)) { |
| 395 |
if (equalIds(id, tgt)) { |
| 396 |
return id; |
| 397 |
} |
| 398 |
} |
| 399 |
return 0; |
| 400 |
} |
| 401 |
|
| 402 |
WId LXQtTaskbarWlrootsBackend::findTopParent(WId winId) const |
| 403 |
{ |
| 404 |
while (getWindow(winId)->parentWindow) |
| 405 |
{ |
| 406 |
winId = getWindow(winId)->parentWindow; |
| 407 |
// first search in transients because this may be a child window of another one |
| 408 |
WId window = 0; |
| 409 |
for (auto i = transients.cbegin(), end = transients.cend(); i != end; ++i) |
| 410 |
{ |
| 411 |
if (equalIds(i.key(), winId)) |
| 412 |
{ |
| 413 |
window = i.key(); |
| 414 |
break; |
| 415 |
} |
| 416 |
} |
| 417 |
if (window) |
| 418 |
winId = window; |
| 419 |
else |
| 420 |
{ |
| 421 |
window = findWindow(winId); |
| 422 |
if (window) |
| 423 |
winId = window; |
| 424 |
} |
| 425 |
} |
| 426 |
return winId; |
| 427 |
} |
| 428 |
|
| 429 |
void LXQtTaskbarWlrootsBackend::addWindow(WId winId) |
| 430 |
{ |
| 431 |
for (auto id : std::as_const(windows)) |
| 432 |
{ |
| 433 |
if (id == winId) |
| 434 |
{ |
| 435 |
return; |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
if (transients.contains(winId)) |
| 440 |
{ |
| 441 |
return; |
| 442 |
} |
| 443 |
|
| 444 |
LXQtTaskbarWlrootsWindow *window = getWindow(winId); |
| 445 |
if (window == nullptr) { |
| 446 |
return; |
| 447 |
} |
| 448 |
|
| 449 |
if (window->windowState.activated) { |
| 450 |
WId pId = findTopParent(winId); |
| 451 |
setLastActivated(pId); |
| 452 |
activeWindow = pId; |
| 453 |
emit activeWindowChanged(activeWindow); |
| 454 |
} |
| 455 |
|
| 456 |
connect(window, &LXQtTaskbarWlrootsWindow::activatedChanged, this, &LXQtTaskbarWlrootsBackend::onActivatedChanged); |
| 457 |
connect(window, &LXQtTaskbarWlrootsWindow::parentChanged, this, &LXQtTaskbarWlrootsBackend::onParentChanged); |
| 458 |
|
| 459 |
// add it either to transients or windows |
| 460 |
if (WId leader = window->parentWindow) |
| 461 |
{ |
| 462 |
transients.insert(winId, leader); |
| 463 |
connect(window, &LXQtTaskbarWlrootsWindow::closed, this, &LXQtTaskbarWlrootsBackend::removeTransient); |
| 464 |
} |
| 465 |
else |
| 466 |
{ |
| 467 |
addToWindows(winId); |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
void LXQtTaskbarWlrootsBackend::addToWindows(WId winId) |
| 472 |
{ |
| 473 |
LXQtTaskbarWlrootsWindow *window = getWindow(winId); |
| 474 |
if (window == nullptr) { |
| 475 |
return; |
| 476 |
} |
| 477 |
|
| 478 |
windows.push_back(winId); |
| 479 |
|
| 480 |
connect(window, &LXQtTaskbarWlrootsWindow::closed, this, &LXQtTaskbarWlrootsBackend::removeWindow); |
| 481 |
connect(window, &LXQtTaskbarWlrootsWindow::titleChanged, this, &LXQtTaskbarWlrootsBackend::onTitleChanged); |
| 482 |
connect(window, &LXQtTaskbarWlrootsWindow::appIdChanged, this, &LXQtTaskbarWlrootsBackend::onAppIdChanged); |
| 483 |
connect(window, &LXQtTaskbarWlrootsWindow::fullscreenChanged, this, &LXQtTaskbarWlrootsBackend::onStateChanged); |
| 484 |
connect(window, &LXQtTaskbarWlrootsWindow::maximizedChanged, this, &LXQtTaskbarWlrootsBackend::onStateChanged); |
| 485 |
connect(window, &LXQtTaskbarWlrootsWindow::minimizedChanged, this, &LXQtTaskbarWlrootsBackend::onStateChanged); |
| 486 |
connect(window, &LXQtTaskbarWlrootsWindow::outputsChanged, this, &LXQtTaskbarWlrootsBackend::onOutputsChanged); |
| 487 |
|
| 488 |
emit windowAdded( winId ); |
| 489 |
emit windowPropertyChanged(winId, int(LXQtTaskBarWindowProperty::WindowClass)); |
| 490 |
emit windowPropertyChanged(winId, int(LXQtTaskBarWindowProperty::Title)); |
| 491 |
emit windowPropertyChanged(winId, int(LXQtTaskBarWindowProperty::Icon)); |
| 492 |
emit windowPropertyChanged(winId, int(LXQtTaskBarWindowProperty::State)); |
| 493 |
} |
| 494 |
|
| 495 |
void LXQtTaskbarWlrootsBackend::removeWindow() |
| 496 |
{ |
| 497 |
if (auto window = qobject_cast<LXQtTaskbarWlrootsWindow *>(QObject::sender())) |
| 498 |
{ |
| 499 |
disconnect(window, &LXQtTaskbarWlrootsWindow::closed, this, &LXQtTaskbarWlrootsBackend::removeWindow); |
| 500 |
disconnect(window, &LXQtTaskbarWlrootsWindow::parentChanged, this, &LXQtTaskbarWlrootsBackend::onParentChanged); |
| 501 |
disconnect(window, &LXQtTaskbarWlrootsWindow::activatedChanged, this, &LXQtTaskbarWlrootsBackend::onActivatedChanged); |
| 502 |
disconnect(window, &LXQtTaskbarWlrootsWindow::titleChanged, this, &LXQtTaskbarWlrootsBackend::onTitleChanged); |
| 503 |
disconnect(window, &LXQtTaskbarWlrootsWindow::appIdChanged, this, &LXQtTaskbarWlrootsBackend::onAppIdChanged); |
| 504 |
disconnect(window, &LXQtTaskbarWlrootsWindow::fullscreenChanged, this, &LXQtTaskbarWlrootsBackend::onStateChanged); |
| 505 |
disconnect(window, &LXQtTaskbarWlrootsWindow::maximizedChanged, this, &LXQtTaskbarWlrootsBackend::onStateChanged); |
| 506 |
disconnect(window, &LXQtTaskbarWlrootsWindow::minimizedChanged, this, &LXQtTaskbarWlrootsBackend::onStateChanged); |
| 507 |
disconnect(window, &LXQtTaskbarWlrootsWindow::outputsChanged, this, &LXQtTaskbarWlrootsBackend::onOutputsChanged); |
| 508 |
|
| 509 |
WId winId = window->getWindowId(); |
| 510 |
eraseWindow(windows, winId); |
| 511 |
lastActivated.remove(winId); |
| 512 |
|
| 513 |
if (activeWindow == winId) |
| 514 |
{ |
| 515 |
activeWindow = 0; |
| 516 |
emit activeWindowChanged(0); |
| 517 |
} |
| 518 |
|
| 519 |
emit windowRemoved(winId); |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
void LXQtTaskbarWlrootsBackend::removeTransient() |
| 524 |
{ |
| 525 |
if (auto window = qobject_cast<LXQtTaskbarWlrootsWindow *>(QObject::sender())) |
| 526 |
{ |
| 527 |
disconnect(window, &LXQtTaskbarWlrootsWindow::closed, this, &LXQtTaskbarWlrootsBackend::removeTransient); |
| 528 |
disconnect(window, &LXQtTaskbarWlrootsWindow::parentChanged, this, &LXQtTaskbarWlrootsBackend::onParentChanged); |
| 529 |
disconnect(window, &LXQtTaskbarWlrootsWindow::activatedChanged, this, &LXQtTaskbarWlrootsBackend::onActivatedChanged); |
| 530 |
transients.remove(window->getWindowId()); |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
void LXQtTaskbarWlrootsBackend::onActivatedChanged() |
| 535 |
{ |
| 536 |
if (auto window = qobject_cast<LXQtTaskbarWlrootsWindow *>(QObject::sender())) |
| 537 |
{ |
| 538 |
WId effectiveWindow = findTopParent(window->getWindowId()); |
| 539 |
|
| 540 |
if (window->windowState.activated) |
| 541 |
{ |
| 542 |
setLastActivated(effectiveWindow); |
| 543 |
|
| 544 |
if (activeWindow != effectiveWindow) |
| 545 |
{ |
| 546 |
activeWindow = effectiveWindow; |
| 547 |
emit activeWindowChanged(activeWindow); |
| 548 |
} |
| 549 |
} |
| 550 |
else |
| 551 |
{ |
| 552 |
// First check if it has an active child (transient) window. |
| 553 |
for (auto i = transients.cbegin(), end = transients.cend(); i != end; ++i) |
| 554 |
{ |
| 555 |
if (window->getWindowId() != i.key() && equalIds(findTopParent(i.key()), effectiveWindow)) |
| 556 |
{ |
| 557 |
if (auto win = getWindow(i.key())) |
| 558 |
{ |
| 559 |
if (win->windowState.activated) |
| 560 |
return; |
| 561 |
} |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
if (activeWindow == effectiveWindow) |
| 566 |
{ |
| 567 |
activeWindow = 0; |
| 568 |
emit activeWindowChanged(0); |
| 569 |
} |
| 570 |
} |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
void LXQtTaskbarWlrootsBackend::onParentChanged() |
| 575 |
{ |
| 576 |
if (auto window = qobject_cast<LXQtTaskbarWlrootsWindow *>(QObject::sender())) |
| 577 |
{ |
| 578 |
WId leader = window->parentWindow; |
| 579 |
|
| 580 |
/** Basically, check if this window is a transient */ |
| 581 |
if (transients.remove(window->getWindowId())) |
| 582 |
{ |
| 583 |
if (leader) |
| 584 |
{ |
| 585 |
// leader change. |
| 586 |
transients.insert(window->getWindowId(), leader); |
| 587 |
} |
| 588 |
else |
| 589 |
{ |
| 590 |
// lost a leader, add to regular windows list. |
| 591 |
Q_ASSERT(findWindow(leader) == 0); |
| 592 |
|
| 593 |
disconnect(window, &LXQtTaskbarWlrootsWindow::closed, this, &LXQtTaskbarWlrootsBackend::removeTransient); |
| 594 |
addToWindows(window->getWindowId()); |
| 595 |
|
| 596 |
// Correct the activation state if an active window that has lost its leader was active before, |
| 597 |
// because "LXQtTaskbarWlrootsWindow::activatedChanged" might not be emitted for it. |
| 598 |
if (window->windowState.activated) |
| 599 |
{ |
| 600 |
setLastActivated(window->getWindowId()); |
| 601 |
activeWindow = window->getWindowId(); |
| 602 |
emit activeWindowChanged(activeWindow); |
| 603 |
} |
| 604 |
} |
| 605 |
} |
| 606 |
else if (leader) |
| 607 |
{ |
| 608 |
// remove it from regular windows list |
| 609 |
disconnect(window, &LXQtTaskbarWlrootsWindow::closed, this, &LXQtTaskbarWlrootsBackend::removeWindow); |
| 610 |
disconnect(window, &LXQtTaskbarWlrootsWindow::titleChanged, this, &LXQtTaskbarWlrootsBackend::onTitleChanged); |
| 611 |
disconnect(window, &LXQtTaskbarWlrootsWindow::appIdChanged, this, &LXQtTaskbarWlrootsBackend::onAppIdChanged); |
| 612 |
disconnect(window, &LXQtTaskbarWlrootsWindow::fullscreenChanged, this, &LXQtTaskbarWlrootsBackend::onStateChanged); |
| 613 |
disconnect(window, &LXQtTaskbarWlrootsWindow::maximizedChanged, this, &LXQtTaskbarWlrootsBackend::onStateChanged); |
| 614 |
disconnect(window, &LXQtTaskbarWlrootsWindow::minimizedChanged, this, &LXQtTaskbarWlrootsBackend::onStateChanged); |
| 615 |
disconnect(window, &LXQtTaskbarWlrootsWindow::outputsChanged, this, &LXQtTaskbarWlrootsBackend::onOutputsChanged); |
| 616 |
eraseWindow(windows, window->getWindowId()); |
| 617 |
lastActivated.remove(window->getWindowId()); |
| 618 |
// announce that it's removed |
| 619 |
emit windowRemoved(window->getWindowId()); |
| 620 |
|
| 621 |
// add it to transients |
| 622 |
transients.insert(window->getWindowId(), leader); |
| 623 |
connect(window, &LXQtTaskbarWlrootsWindow::closed, this, &LXQtTaskbarWlrootsBackend::removeTransient); |
| 624 |
|
| 625 |
// Correct the activation state if a window that has got a leader was active before. |
| 626 |
if (activeWindow == window->getWindowId()) |
| 627 |
{ |
| 628 |
WId pId = findTopParent(window->getWindowId()); |
| 629 |
setLastActivated(pId); |
| 630 |
activeWindow = pId; |
| 631 |
emit activeWindowChanged(activeWindow); |
| 632 |
} |
| 633 |
} |
| 634 |
} |
| 635 |
} |
| 636 |
|
| 637 |
void LXQtTaskbarWlrootsBackend::onTitleChanged() |
| 638 |
{ |
| 639 |
if (auto window = qobject_cast<LXQtTaskbarWlrootsWindow *>(QObject::sender())) |
| 640 |
emit windowPropertyChanged(window->getWindowId(), int(LXQtTaskBarWindowProperty::Title)); |
| 641 |
} |
| 642 |
|
| 643 |
void LXQtTaskbarWlrootsBackend::onAppIdChanged() |
| 644 |
{ |
| 645 |
if (auto window = qobject_cast<LXQtTaskbarWlrootsWindow *>(QObject::sender())) |
| 646 |
emit windowPropertyChanged(window->getWindowId(), int(LXQtTaskBarWindowProperty::WindowClass)); |
| 647 |
} |
| 648 |
|
| 649 |
void LXQtTaskbarWlrootsBackend::onStateChanged() |
| 650 |
{ |
| 651 |
if (auto window = qobject_cast<LXQtTaskbarWlrootsWindow *>(QObject::sender())) |
| 652 |
emit windowPropertyChanged(window->getWindowId(), int(LXQtTaskBarWindowProperty::State)); |
| 653 |
} |
| 654 |
|
| 655 |
void LXQtTaskbarWlrootsBackend::onOutputsChanged() |
| 656 |
{ |
| 657 |
if (auto window = qobject_cast<LXQtTaskbarWlrootsWindow *>(QObject::sender())) |
| 658 |
emit windowPropertyChanged(window->getWindowId(), int(LXQtTaskBarWindowProperty::Geometry)); |
| 659 |
} |
| 660 |
|
| 661 |
bool LXQtTaskbarWlrootsBackend::acceptWindow(WId window) const |
| 662 |
{ |
| 663 |
if(transients.contains(window)) |
| 664 |
return false; |
| 665 |
|
| 666 |
return true; |
| 667 |
} |
| 668 |
|
| 669 |
LXQtTaskbarWlrootsWindow *LXQtTaskbarWlrootsBackend::getWindow(WId windowId) const |
| 670 |
{ |
| 671 |
/** Easiest way is to convert the quintptr to the actual pointer */ |
| 672 |
LXQtTaskbarWlrootsWindow *win = reinterpret_cast<LXQtTaskbarWlrootsWindow *>( windowId ); |
| 673 |
if ( win ) { |
| 674 |
return win; |
| 675 |
} |
| 676 |
|
| 677 |
return nullptr; |
| 678 |
} |
| 679 |
|
| 680 |
bool LXQtTaskbarWlrootsBackend::equalIds(WId windowId1, WId windowId2) const |
| 681 |
{ |
| 682 |
if (windowId1 == windowId2) { |
| 683 |
return true; |
| 684 |
} |
| 685 |
LXQtTaskbarWlrootsWindow *win1 = reinterpret_cast<LXQtTaskbarWlrootsWindow *>( windowId1 ); |
| 686 |
LXQtTaskbarWlrootsWindow *win2 = reinterpret_cast<LXQtTaskbarWlrootsWindow *>( windowId2 ); |
| 687 |
if (win1 == nullptr && win2 == nullptr) { |
| 688 |
return true; |
| 689 |
} |
| 690 |
if (win1 != nullptr && win2 != nullptr) { |
| 691 |
return win1->ID == win2->ID; |
| 692 |
} |
| 693 |
return false; |
| 694 |
} |
| 695 |
|
| 696 |
void LXQtTaskbarWlrootsBackend::setLastActivated(WId id) |
| 697 |
{ |
| 698 |
auto t = QDateTime::currentMSecsSinceEpoch(); |
| 699 |
while (lastActivated.key(t) != 0) |
| 700 |
++t; // make sure the times are not equal |
| 701 |
lastActivated[id] = t; |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
int LXQtWMBackendWlrootsLibrary::getBackendScore(const QString& key) const |
| 706 |
{ |
| 707 |
if (key.compare(QStringLiteral("wlroots"), Qt::CaseInsensitive) == 0) |
| 708 |
{ |
| 709 |
return 50; |
| 710 |
} |
| 711 |
|
| 712 |
static const QStringList supportedList = {QStringLiteral("labwc"), |
| 713 |
QStringLiteral("sway"), |
| 714 |
QStringLiteral("wayfire"), |
| 715 |
// The following compositors are also supported, |
| 716 |
// although they are not based on wlroots. |
| 717 |
QStringLiteral("hyprland"), |
| 718 |
QStringLiteral("river"), |
| 719 |
QStringLiteral("niri")}; |
| 720 |
if (supportedList.contains(key, Qt::CaseInsensitive)) |
| 721 |
{ |
| 722 |
return 30; |
| 723 |
} |
| 724 |
|
| 725 |
// Unsupported |
| 726 |
return 0; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
ILXQtAbstractWMInterface *LXQtWMBackendWlrootsLibrary::instance() const |
| 731 |
{ |
| 732 |
return new LXQtTaskbarWlrootsBackend(nullptr); |
| 733 |
} |