Add KuroWMII layout that manages new windows in a way I like, add some more shortcuts, improve battery icon, automatically open programs on workspaces and remove the GroupRules for them after they spawn so that new instances of that app don't open on that workspace any more.

This commit is contained in:
Kevin Alberts 2017-12-02 09:29:26 +01:00
parent b9224b667d
commit 9a3fdf1b65
5 changed files with 176 additions and 14 deletions

View file

@ -1,10 +1,12 @@
import os
import re
import subprocess
from time import sleep
import cairocffi
import notify2
from libqtile import widget, bar
from libqtile.window import Internal
from libqtile.bar import Bar
from libqtile.utils import catch_exception_and_warn, UnixCommandNotFound
from libqtile.widget import base
@ -13,6 +15,7 @@ from libqtile.widget.check_updates import CheckUpdates
from libqtile.widget.image import Image
from libqtile.widget.sensors import ThermalSensor
from libqtile.widget.volume import Volume
from libqtile.widget.battery import BatteryIcon
from libqtile.widget.wlan import get_status
from libqtile.log_utils import logger
from notify2 import Notification, URGENCY_NORMAL
@ -80,13 +83,45 @@ def notify(title, content, urgency=URGENCY_NORMAL, timeout=5000, image=None):
def spawn_popup(qtile, x, y, text):
"""
:param qtile: The main qtile instance
:type qtile: Qtile
:param x: x-coordinate
:type x: int
:param y: y-coordinate
:type y: int
:param text: String to display
:type text: str
:return: The popup instance
:rtype: Internal
"""
popup = Internal.create(
qtile, x, y, 100, 100, opacity=1
)
# Create textwidget for in window
pass
popup.bordercolor = "#000000"
popup.borderwidth = 1
popup.focus(False)
#popup.
return popup
# window.Internal.create(
# qtile, x, y, width, height, opacity=1
# )
def despawn_popup(popup):
"""
:type popup: Internal
:param popup: The popup to despawn
"""
popup.kill()
def test_popups(qtile):
popup = spawn_popup(qtile, 10, 10, "Hello World!")
sleep(3)
despawn_popup(popup)
def display_wm_class(qtile):
@ -218,6 +253,17 @@ class CheckUpdatesYaourt(CheckUpdates):
elif button == BUTTON_MIDDLE and self.execute is not None:
subprocess.Popen(self.execute, shell=True)
class KuroBatteryIcon(BatteryIcon):
status_cmd = "acpi"
def button_press(self, x, y, button):
if button == BUTTON_LEFT:
output = subprocess.check_output(self.status_cmd).decode('utf-8')
notify(
"Battery Status",
output
)
class PulseVolumeWidget(Volume):

View file

@ -59,7 +59,7 @@ def handle_focus_change(theme):
name = window.name
if wm_class:
theme.log_info(str(wm_class))
theme.log_info("{}, {}".format(wm_class, name))
# Check which window we entered and do some special effects if it is a special window.

51
kuro/utils/layouts.py Normal file
View file

@ -0,0 +1,51 @@
from libqtile.layout.wmii import Wmii
class KuroWmii(Wmii):
def cmd_previous(self):
super(KuroWmii, self).cmd_previous()
def cmd_next(self):
super(KuroWmii, self).cmd_next()
def add(self, client):
"""
Add a new client window to the layout and focus it. It will be added to either the current column if there
are less rows in the current column than columns on the screen, or to a new row to the right of the current
column if there are less columns than rows in the current column.
:param client: The client window to add.
"""
self.clients.append(client)
c = self.current_column()
if c is None:
if len(self.columns) == 0:
self.columns = [{'active': 0, 'width': 100, 'mode': 'split', 'rows': []}]
c = self.columns[0]
c['rows'].append(client)
else:
num_cols = len(self.columns)
num_rows_curr_col = len(c['rows'])
if num_rows_curr_col < num_cols:
c['rows'].append(client)
else:
self.add_column_to_right(c, client)
self.focus(client)
def add_column_to_right(self, column, win):
"""
Adds a new column to the right of the given column with the given window in it
:param column: The column that's going to be to the left of the new column
:param win: The window to add to the new column
"""
newwidth = int(100 / (len(self.columns) + 1))
# we are only called if there already is a column, simplifies things
for c in self.columns:
c['width'] = newwidth
c = {'width': newwidth, 'mode': 'split', 'rows': [win]}
try:
index = self.columns.index(column) + 1
except ValueError:
index = 0
self.columns.insert(index, c)