2017-09-15 17:51:14 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Displays focused i3 window title.
|
|
|
|
|
|
|
|
Requirements:
|
|
|
|
* i3ipc
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* title.max : Maximum character length for title before truncating. Defaults to 64.
|
|
|
|
* title.placeholder : Placeholder text to be placed if title was truncated. Defaults to "...".
|
2017-09-16 01:46:24 +02:00
|
|
|
* title.scroll : Boolean flag for scrolling title. Defaults to False
|
2017-09-15 17:51:14 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
import i3ipc
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
import bumblebee.util
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
2017-09-16 01:46:24 +02:00
|
|
|
from bumblebee.output import scrollable
|
|
|
|
|
2017-10-27 10:42:10 +02:00
|
|
|
no_title = "n/a"
|
|
|
|
|
2017-09-15 17:51:14 +02:00
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
"""Window title module."""
|
|
|
|
|
|
|
|
def __init__(self, engine, config):
|
2017-09-15 18:03:58 +02:00
|
|
|
super(Module, self).__init__(
|
|
|
|
engine,
|
|
|
|
config,
|
2017-09-16 01:46:24 +02:00
|
|
|
bumblebee.output.Widget(full_text=self.get_title)
|
2017-09-15 17:51:14 +02:00
|
|
|
)
|
2017-09-15 20:05:09 +02:00
|
|
|
try:
|
|
|
|
self._i3 = i3ipc.Connection()
|
|
|
|
self._full_title = self._i3.get_tree().find_focused().name
|
|
|
|
except Exception:
|
2017-10-27 10:42:10 +02:00
|
|
|
self._full_title = no_title
|
2017-09-15 17:51:14 +02:00
|
|
|
|
2017-09-16 01:46:24 +02:00
|
|
|
def get_title(self, widget):
|
2017-09-18 08:30:44 +02:00
|
|
|
if bumblebee.util.asbool(self.parameter("scroll", False)):
|
2017-09-16 01:46:24 +02:00
|
|
|
return self.scrolling_focused_title(widget)
|
|
|
|
else:
|
|
|
|
return self.focused_title(widget)
|
|
|
|
|
2017-09-15 20:00:57 +02:00
|
|
|
def focused_title(self, widget):
|
2019-05-20 20:33:19 +02:00
|
|
|
max = int(self.parameter("max", 64))
|
|
|
|
title = self._full_title[0:max]
|
2017-09-16 01:46:24 +02:00
|
|
|
placeholder = self.parameter("placeholder", "...")
|
2017-09-15 20:00:57 +02:00
|
|
|
if title != self._full_title:
|
2019-05-20 20:33:19 +02:00
|
|
|
title = self._full_title[0:max - len(placeholder)]
|
2017-09-16 01:46:24 +02:00
|
|
|
title = "{}{}".format(title, placeholder)
|
2017-09-15 20:00:57 +02:00
|
|
|
|
|
|
|
return title
|
2017-09-15 17:51:14 +02:00
|
|
|
|
2017-09-16 01:46:24 +02:00
|
|
|
@scrollable
|
|
|
|
def scrolling_focused_title(self, widget):
|
|
|
|
return self._full_title
|
|
|
|
|
2017-09-15 17:51:14 +02:00
|
|
|
def update(self, widgets):
|
|
|
|
"""Update current title."""
|
2017-09-15 20:05:09 +02:00
|
|
|
try:
|
|
|
|
self._full_title = self._i3.get_tree().find_focused().name
|
|
|
|
except Exception:
|
2017-10-27 10:42:10 +02:00
|
|
|
self._full_title = no_title
|
|
|
|
|
2018-06-04 15:03:39 +02:00
|
|
|
if self._full_title is None:
|
2017-10-27 10:42:10 +02:00
|
|
|
self._full_title = no_title
|
2017-09-15 17:51:14 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|