This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Programatically Hide Window Titlebar of Maximized Window

Tags: None
(comma "," separated)
compmodder26
Registered Member
Posts
2
Karma
0
OS
Let me preface this post by saying that I have very little experience programming in c++ and working with KDE development.

I am developing a plasmoid similar to http://kde-apps.org/content/show.php/Yet+Another+Window+Control?content=139916. Except I am mainly re-purposing it to only work with the active maximized window. So if no windows are maximized then the plasmoid is hidden and it only operates on the active maximized window.

That part I have covered and is working wonderfully.

The part that I want to get a grasp over is how to hide the titlebar of the active maximized window. I know I can add "BorderlessMaximizedWindows=true" to the user's kwinrc, but I wish to hide the titlebar programatically to avoid messing with the user's settings and to also ensure that if the plasmoid is removed that maximized windows will behave like they did before the plasmoid was added.

Here is the method that handles detecting the maximized window and setting up the window controls for it. Could somebody give me a hint as to how I can hide the titlebar?

Code: Select all
void MaxWinControl::syncActiveWindow()
{
    m_syncDelay = false;
    bool applicationActive = false;
 
    foreach (QWidget *widget, QApplication::topLevelWidgets()) {
         if (widget->winId() == m_pendingActiveWindow ||
             widget->winId() == KWindowSystem::activeWindow()) {
             applicationActive = true;
             break;
         }
     }
     
    if (applicationActive && m_pendingActiveWindow > 0) {
        m_closeTask->hide();
        m_maximizeTask->hide();
        m_minimizeTask->hide();
   m_currentTaskTitle->hide();
   m_currentTaskIcon->hide();
    } else if (m_pendingActiveWindow > 0) {
      m_activeWindow = m_pendingActiveWindow;
      m_lastActiveWindow = m_pendingActiveWindow;
      KWindowInfo info = KWindowSystem::windowInfo(m_activeWindow, NET::WMName|NET::WMState);
     
      if (info.state() & NET::Max) {
   if (m_showTitle) {
     m_currentTaskTitle->setText(info.name());
     m_currentTaskTitle->update();
    
     m_currentTaskTitle->show();
   }
 
        if (m_showClose) {
            m_closeTask->show();
        }
        if (m_showMaximize) {
            m_maximizeTask->show();
        }
        if (m_showMinimize) {
            m_minimizeTask->show();
        }
       
        if (m_showCurrentTaskIcon) {
       m_currentTaskIcon->setIcon(KWindowSystem::icon(m_activeWindow, KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium));
    
       m_currentTaskIcon->show();
   }
 
        m_maximizeTask->setSvg("widgets/configuration-icons", "unmaximize");
      }
      else {
   m_closeTask->hide();
        m_maximizeTask->hide();
        m_minimizeTask->hide();
   m_currentTaskTitle->hide();
   m_currentTaskIcon->hide();
      }
    }
 
    m_pendingActiveWindow = 0;
}
compmodder26
Registered Member
Posts
2
Karma
0
OS
So I found that you can get and set window flags http://doc.qt.nokia/latest/qt.html/#WindowType-enum through the QWidget class. The flag I'm specifically wanting to set is Qt::FramelessWindowHint. I'm supposed to be able to pass the window id of the active window to QWidget's find() function and it will return a QWidget object so I can manipulate the window flags. However, it always returns 0 (not found).

Here is a stub of the function above that includes the code I've put in. Any ideas on why QWidget::find() always returns 0 even though the window ID passed to it obviously belongs to a valid window?
Code: Select all
void MaxWinControl::syncActiveWindow()
{
    m_syncDelay = false;
    bool applicationActive = false;
   
    foreach (QWidget *widget, QApplication::topLevelWidgets()) {
         if (widget->winId() == m_pendingActiveWindow ||
             widget->winId() == KWindowSystem::activeWindow()) {
             applicationActive = true;
   
             break;
         }
     }
     
    if (applicationActive && m_pendingActiveWindow > 0) {
        m_closeTask->hide();
        m_maximizeTask->hide();
        m_minimizeTask->hide();
   m_currentTaskTitle->hide();
   m_currentTaskIcon->hide();
    } else if (m_pendingActiveWindow > 0) {
      m_activeWindow = m_pendingActiveWindow;
      m_lastActiveWindow = m_pendingActiveWindow;
      KWindowInfo info = KWindowSystem::windowInfo(m_activeWindow, NET::WMName|NET::WMState);
     
      if (info.state() & NET::Max) {
   QWidget *activeWidget = QWidget::find(m_activeWindow);
     
   if (activeWidget) {
          // store the previous flags for this window so we can restore them when the window is unmaximized
     activeWidgetFlags = activeWidget->windowFlags();
    
     activeWidget->setWindowFlags(Qt::FramelessWindowHint);
    
     activeWidget->show();
   }
...


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft