wavexx / screenkey

A screencast tool to display your keys inspired by Screenflick
https://www.thregr.org/~wavexx/software/screenkey/
GNU General Public License v3.0
757 stars 66 forks source link

Add support to set background transparency independently (fixes #47) #66

Closed zaygraveyard closed 6 years ago

zaygraveyard commented 6 years ago

Uses cairo to draw the background of the window

ghost commented 6 years ago

Can you try to pip install pycairo?

@zaygraveyard, can't install it on MX Linux MX-17 (aka Debian 9 "Stretch")

$ sudo pip install pycairo
The directory '/home/mint/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/mint/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pycairo
  Downloading pycairo-1.16.3.tar.gz (188kB)
    100% |████████████████████████████████| 194kB 19kB/s 
Installing collected packages: pycairo
  Running setup.py install for pycairo ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/var/tmp/pip-build-qbB9Kh/pycairo/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-aNLxaQ-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/cairo
    copying cairo/__init__.py -> build/lib.linux-x86_64-2.7/cairo
    copying cairo/__init__.pyi -> build/lib.linux-x86_64-2.7/cairo
    running build_ext
    'pkg-config' not found.
    Command ['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/var/tmp/pip-build-qbB9Kh/pycairo/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-aNLxaQ-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /var/tmp/pip-build-qbB9Kh/pycairo/
zaygraveyard commented 6 years ago

@Symbian9 pkg-config is a dependency of pycairo and it doesn't seams to be installed on your system. Can you try sudo apt-get install pkg-config?

ghost commented 6 years ago

Can you try sudo apt-get install pkg-config?

pkg-config just installed, but something wrong with cairo

$ sudo pip install pycairo
The directory '/home/mint/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/mint/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pycairo
  Downloading https://files.pythonhosted.org/packages/60/47/d335364f0ca00e475a40a5a664f17691bf77b3973f999b157d56ee89e04a/pycairo-1.17.0.tar.gz (192kB)
    100% |████████████████████████████████| 194kB 43kB/s 
Installing collected packages: pycairo
  Running setup.py install for pycairo ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/var/tmp/pip-build-noo0TB/pycairo/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-mueWew-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/cairo
    copying cairo/__init__.py -> build/lib.linux-x86_64-2.7/cairo
    copying cairo/__init__.pyi -> build/lib.linux-x86_64-2.7/cairo
    copying cairo/py.typed -> build/lib.linux-x86_64-2.7/cairo
    running build_ext
    Package cairo was not found in the pkg-config search path.
    Perhaps you should add the directory containing `cairo.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'cairo' found
    Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']' returned non-zero exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/var/tmp/pip-build-noo0TB/pycairo/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-mueWew-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /var/tmp/pip-build-noo0TB/pycairo/
zaygraveyard commented 6 years ago

@Symbian9 can you try sudo apt-get install libcairo2-dev? Sorry I don't have my hands on a debian machine so I can't test 😟

ghost commented 6 years ago

Just install pycairo, but still has no transparency effect. How enable transparency?

zaygraveyard commented 6 years ago

The issue that this PR solves is that the opacity parameter (--opacity or "Opacity" in the settings dialog) changes the transparency of the whole window (including the text), which means it was impossible to have a transparent background with opaque text.

To test it you can change the opacity parameter and observe that the text remains fully opaque while the transparency of the background changes.

ghost commented 6 years ago

To test it you can change the opacity parameter and observe that the text remains fully opaque while the transparency of the background changes.

@zaygraveyard, there NO difference after opacity changed:

Opacity 0.1 Opacity 0.1

Opacity 1.0 Opacity 1.0

Also, on start (I try latest screenkey without install) Screenkey return some issue in terminal output:

mint@mx1:~/Downloads/screenkey-develop
$ python2.7 ./screenkey
mint@mx1:~/Downloads/screenkey-develop
$ /home/mint/Downloads/screenkey-develop/Screenkey/screenkey.py:916: Warning: /build/glib2.0-B1uXKV/glib2.0-2.50.3/./gobject/gsignal.c:2523: signal 'child-added' is invalid for instance '0x5619542d67a0' of type 'GtkMenu'
  self.systray.set_menu(self.menu)

After start latest Screenkey also overload CPU (I have NO such issue with previous 0.9 release version):

CPU overload

wavexx commented 6 years ago

Thanks a lot for this. Merged with minimal tweaks. I tried also to see if we could change the opacity of the text itself, but this is another case where the required functionality is again only through the newer gobject API.

zaygraveyard commented 6 years ago

@Symbian9 Sorry for the late response. I don't know why the opacity didn't work on your system :disappointed: Can you try my develop branch with a -d or --debug a see if "RGBA colormap not supported!" is logged?

I fixed the CPU usage issue which was caused by #65 see https://github.com/wavexx/screenkey/pull/65/commits/287dab174eb14413bba3ddaeb55a7e17f5f83880

ghost commented 6 years ago

@zaygraveyard, I just try your develop branch - still not got transparency.

Here is what I see in terminal

$ ./screenkey -d
DEBUG:Screenkey:Options loaded.
DEBUG:Screenkey:Restarting LabelManager.
DEBUG:Screenkey:Thread started.
DEBUG:Screenkey:Mouse changed: True.
/home/mint/Downloads/screenkey-develop/Screenkey/screenkey.py:948: Warning: /build/glib2.0-B1uXKV/glib2.0-2.50.3/./gobject/gsignal.c:2523: signal 'child-added' is invalid for instance '0x559bb767b7a0' of type 'GtkMenu'
  self.systray.set_menu(self.menu)
DEBUG:Screenkey:Using AppIndicator.
DEBUG:Screenkey:Mouse button 3 pressed
DEBUG:Screenkey:Mouse button 3 released
...

That's all.

zaygraveyard commented 6 years ago

@Symbian9, In that case, I'm stumped :worried: