Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89413

Add support for _NET_WM_STATE_SKIP_TASKBAR window state (skip taskbar) on openbox/tint2

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Do
    • P4: Low
    • None
    • 5.15.2
    • QPA: X11/XCB
    • None
    • Linux peppy 5.4.79-1-lts #1 SMP Sun, 22 Nov 2020 14:22:21 +0000 x86_64 GNU/Linux
      python-pyqt5 5.15.2-1

    • Linux/X11

    Description

      In Windows, the application can be hidden from taskbar simply by adding a windowFlag, which is very handy;

      self.setWindowFlags(self.windowFlags() | QtCore.Qt.Tool)
      

       

      On Linux however, there is no native solution that works across all desktop environments. A simple solution for X11 would be to add a windowFlag that would set the _NET_WM_STATE_SKIP_TASKBAR on the window. The current way to do this is to invoke an  external program (xprop) every time the window is shown, along with some cryptic code;

      #!/usr/bin/python3
      import ctypes
      import sys
      from PyQt5 import QtWidgets, QtCore
      
      
      class Window(QtWidgets.QWidget):
          def __init__(self):
              super().__init__()
              self._skipTaskbar()
              self.show()
      
          def showEvent(self, event):
              """ Hide the note from the taskbar, survive show/hide """
              if sys.platform.startswith("linux"):
                  self.xprop.start()
                  self.xprop.waitForFinished()
      
          def _skipTaskbar(self):
              """ Hide the note from the system taskbar """
              if sys.platform.startswith("win"):
                  self.setWindowFlags(self.windowFlags() | QtCore.Qt.Tool)
      
              elif sys.platform.startswith("linux"):
                  # X11: Manually set the _NET_WM_STATE_SKIP_TASKBAR flag on each window
                  # Avoid various WM issues related with WA_X11NetWmWindowType*
                  ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
                  ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p]
                  wid = ctypes.pythonapi.PyCapsule_GetPointer(self.winId().ascapsule(), None)
                  cmd = f"-id {wid} -f _NET_WM_STATE 32a -set _NET_WM_STATE _NET_WM_STATE_SKIP_TASKBAR"
                  self.xprop = QtCore.QProcess()
                  self.xprop.setProgram("xprop")
                  self.xprop.setArguments(cmd.split())
      
      if __name__ == "__main__":
          app = QtWidgets.QApplication([])
          gui = Window()
          app.exec()

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            liaqi Liang Qi
            william.belanger William Belanger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes