You are not logged in.

#1 2018-01-20 14:04:10

decadentgray
Member
Registered: 2014-10-16
Posts: 8

Creating desktop panel pager in python

Hi Folks,

I'm currently writing on a desktop panel, and wish to implement a pager, for which I need to know on which desktop I currently am.
Since I'm not a Xlib crack, I'm using python ewmh and poll for changes (sample code below),
and it works like a charm, but of course hogs some cpu-time.
I capped it by slowing it to 30 frames per second ( time.sleep( 0.03) ), so it 'only' eats up about 0,7 to 1,6% of my cpu (according to top), which is okeyish.

Since the panel is written with qt5, I'm really hesitant to use libwnck (which might be a bit faster, but pulls in some gnome stuff as far as I have seen),
so maybe someone has any cool ideas for optimizations, or any way to not poll but get woken up on desktop change, or any qt5 trickery which might improve the job?

Any help would be greatly appreciated wink



#!/usr/bin/python3

import time
from ewmh import EWMH
ewmh = EWMH()

numDesks = ewmh.getNumberOfDesktops()
currentDesk = ewmh.getCurrentDesktop()

while True:
    if currentDesk == ewmh.getCurrentDesktop():
        pass
    else:
        currentDesk = ewmh.getCurrentDesktop()
        # Here comes the ui code so the panel shows
        # the current dekstop to the user.
        # ----
    # sleep to poll at roughly 30fps, so the update on the
    # ui is more or less 'instantly' visible, doesn't feel
    # laggy but doesn't hog too much cpu.
    time.sleep( 0.03)

Last edited by decadentgray (2018-01-20 16:12:40)

Offline

#2 2018-01-20 14:10:05

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,848
Website

Re: Creating desktop panel pager in python

Please remove the superfluous "[Help needed]" tag and change your topic title to something that describes what you're trying to accomplish, e.g. "Creating desktop panel pager in python".

https://wiki.archlinux.org/index.php/Co … ow_to_post


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#3 2018-01-20 16:13:50

decadentgray
Member
Registered: 2014-10-16
Posts: 8

Re: Creating desktop panel pager in python

Sorry, no bad intent here, changed it.

Offline

Board footer

Powered by FluxBB