source: lumina/lumina-desktop/panel-plugins/systemtray/LSysTray.cpp @ c78ef7c

releng/10.0.3releng/10.1
Last change on this file since c78ef7c was c78ef7c, checked in by Ken Moore <ken@…>, 5 months ago

Fix the issue with menu's showing up on the screen when the toolbar is vertical (the X11 screen reservation function also needed to be vertical-toolbar aware in libLumina).
ALso clean up the general system tray appearance, and add a new virtual function for panel plugins to detect when the toolbar orientation might have changed and update appropriately. The system tray uses this function now (and it works really well), but the rest of the plugins need to add this functionality as well - otherwise sizes and such get all screwed up when switching between horizontal/vertical.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1//===========================================
2//  Lumina-DE source code
3//  Copyright (c) 2012, Ken Moore
4//  Available under the 3-clause BSD license
5//  See the LICENSE file for full details
6//===========================================
7#include "LSysTray.h"
8
9LSysTray::LSysTray(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){
10  frame = new QFrame(this);
11  frame->setContentsMargins(0,0,0,0);
12  frame->setStyleSheet("QFrame{ background: black; border: 1px solid grey; border-radius: 5px; }");
13  LI = new QBoxLayout( this->layout()->direction(), this);
14    frame->setLayout(LI);
15    LI->setAlignment(Qt::AlignCenter);
16    LI->setSpacing(1);
17    LI->setContentsMargins(0,0,0,0);
18  this->layout()->addWidget(frame);
19  this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
20  isRunning = false;
21  start();
22}
23
24LSysTray::~LSysTray(){
25 if(isRunning){
26   this->stop();
27 }
28}
29
30void LSysTray::start(){
31  if(LSession::StartupSystemTray()){
32    //Now connect the application signals to the X event parser
33    connect(LSession::instance(),SIGNAL(NewSystemTrayApp(WId)),this,SLOT(addTrayIcon(WId)) );
34    qDebug() << "System Tray Started Successfully";
35    isRunning = true;
36  }
37}
38
39void LSysTray::stop(){
40  if(!isRunning){ return; }
41  //Release all the tray applications and delete the containers
42  for(int i=(trayIcons.length()-1); i>=0; i--){
43    trayIcons[i]->detachApp();
44    delete trayIcons.takeAt(i);
45  }
46  //Now close down the tray
47  LSession::CloseSystemTray();
48
49  disconnect(this);
50  isRunning = false;
51}
52
53// ========================
54//    PRIVATE FUNCTIONS
55// ========================
56void LSysTray::addTrayIcon(WId win){
57  if(win == 0 || !isRunning){ return; }
58  //qDebug() << "System Tray: Add Tray Icon:" << win;
59  bool exists = false;
60  for(int i=0; i<trayIcons.length(); i++){
61    if(trayIcons[i]->appID() == win){ exists=true; break; }
62  }
63  if(!exists){
64    //qDebug() << " - New Icon";
65    TrayIcon *cont = new TrayIcon(this);
66      connect(cont, SIGNAL(AppClosed()), this, SLOT(trayAppClosed()) );
67      connect(cont, SIGNAL(AppAttached()), this, SLOT(updateStatus()) );
68      trayIcons << cont;
69      LI->addWidget(cont);
70      if(this->layout()->direction()==QBoxLayout::LeftToRight){
71        cont->setSizeSquare(this->height()-2*frame->frameWidth()); //horizontal tray
72        this->setMaximumSize( trayIcons.length()*this->height(), 10000);
73      }else{
74        cont->setSizeSquare(this->width()-2*frame->frameWidth()); //vertical tray
75        this->setMaximumSize(10000, trayIcons.length()*this->width());
76      }
77      cont->attachApp(win);
78    //this->layout()->update(); //make sure there is no blank space
79  }
80}
81
82void LSysTray::updateStatus(){
83  qDebug() << "System Tray: Client Attached";
84  this->layout()->update(); //make sure there is no blank space
85  //qDebug() << " - Items:" << trayIcons.length();
86}
87
88void LSysTray::trayAppClosed(){
89  for(int i=0;  i<trayIcons.length(); i++){
90    if(trayIcons[i]->appID() == 0){
91      qDebug() << "System Tray: Removing icon";
92      TrayIcon *cont = trayIcons.takeAt(i);
93      LI->removeWidget(cont);
94      delete cont;
95    }
96  }
97  //Re-adjust the maximum widget size
98  if(this->layout()->direction()==QBoxLayout::LeftToRight){
99    this->setMaximumSize( trayIcons.length()*this->height(), 10000);
100  }else{
101    this->setMaximumSize(10000, trayIcons.length()*this->width());
102  }
103  LI->update(); //update the layout (no gaps)
104  this->update();       
105}
106
Note: See TracBrowser for help on using the repository browser.