/usr/lib/python3/dist-packages/libqtile/hook.py is in python3-qtile 0.10.7-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | # Copyright (c) 2009-2010 Aldo Cortesi
# Copyright (c) 2010 Lee McCuller
# Copyright (c) 2010 matt
# Copyright (c) 2010, 2014 dequis
# Copyright (c) 2010, 2012, 2014 roger
# Copyright (c) 2011 Florian Mounier
# Copyright (c) 2011 Kenji_Takahashi
# Copyright (c) 2011 Paul Colomiets
# Copyright (c) 2011 Tzbob
# Copyright (c) 2012-2015 Tycho Andersen
# Copyright (c) 2012 Craig Barnes
# Copyright (c) 2013 Tao Sauvage
# Copyright (c) 2014 Sean Vig
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from .log_utils import logger
from . import utils
subscriptions = {}
SKIPLOG = set()
qtile = None
def init(q):
global qtile
qtile = q
def clear():
subscriptions.clear()
class Subscribe(object):
def __init__(self):
hooks = set([])
for i in dir(self):
if not i.startswith("_"):
hooks.add(i)
self.hooks = hooks
def _subscribe(self, event, func):
lst = subscriptions.setdefault(event, [])
if func not in lst:
lst.append(func)
def startup_once(self, func):
"""Called when Qtile has started on first start
This hook is called exactly once per session (i.e. not on each
``lazy.restart()``).
**Arguments**
None
"""
return self._subscribe("startup_once", func)
def startup(self, func):
"""Called when qtile is started
**Arguments**
None
"""
return self._subscribe("startup", func)
def startup_complete(self, func):
"""Called when qtile is started after all resources initialized
**Arguments**
None
"""
return self._subscribe("startup_complete", func)
def setgroup(self, func):
"""Called when group is changed
**Arguments**
None
"""
return self._subscribe("setgroup", func)
def addgroup(self, func):
"""Called when group is added
**Arguments**
* qtile manager instance
* name of new group
"""
return self._subscribe("addgroup", func)
def delgroup(self, func):
"""Called when group is deleted
**Arguments**
* qtile manager instance
* name of deleted group
"""
return self._subscribe("delgroup", func)
def changegroup(self, func):
"""Called whenever a group change occurs
**Arguments**
None
"""
return self._subscribe("changegroup", func)
def focus_change(self, func):
"""Called when focus is changed
**Arguments**
None
"""
return self._subscribe("focus_change", func)
def float_change(self, func):
"""Called when a change in float state is made
**Arguments**
None
"""
return self._subscribe("float_change", func)
def group_window_add(self, func):
"""Called when a new window is added to a group
**Arguments**
None
"""
return self._subscribe("group_window_add", func)
def window_name_change(self, func):
"""Called whenever a windows name changes
**Arguments**
None
"""
return self._subscribe("window_name_change", func)
def client_new(self, func):
"""Called before Qtile starts managing a new client
Use this hook to declare windows static, or add them to a group on
startup. This hook is not called for internal windows.
**Arguments**
* ``window.Window`` object
Examples
--------
::
@libqtile.hook.subscribe.client_new
def func(c):
if c.name == "xterm":
c.togroup("a")
elif c.name == "dzen":
c.static(0)
"""
return self._subscribe("client_new", func)
def client_managed(self, func):
"""Called after Qtile starts managing a new client
Called after a window is assigned to a group, or when a window is made
static. This hook is not called for internal windows.
**Arguments**
* ``window.Window`` object of the managed window
"""
return self._subscribe("client_managed", func)
def client_killed(self, func):
"""Called after a client has been unmanaged
**Arguments**
* ``window.Window`` object of the killed window.
"""
return self._subscribe("client_killed", func)
def client_state_changed(self, func):
"""Called whenever client state changes
Never fires
"""
return self._subscribe("client_state_changed", func)
def client_type_changed(self, func):
"""Called whenever window type changes
Never fires
"""
return self._subscribe("client_type_changed", func)
def client_focus(self, func):
"""Called whenever focus changes
**Arguments**
* ``window.Window`` object of the new focus.
"""
return self._subscribe("client_focus", func)
def client_mouse_enter(self, func):
"""Called when the mouse enters a client
**Arguments**
* ``window.Window`` of window entered
"""
return self._subscribe("client_mouse_enter", func)
def client_name_updated(self, func):
"""Called when the client name changes
Never fires
"""
return self._subscribe("client_name_updated", func)
def client_urgent_hint_changed(self, func):
"""Called when the client urgent hint changes
**Arguments**
* ``window.Window`` of client with hint change
"""
return self._subscribe("client_urgent_hint_changed", func)
def layout_change(self, func):
"""Called on layout change
**Arguments**
* layout object for new layout
* group object on which layout is changed
"""
return self._subscribe("layout_change", func)
def net_wm_icon_change(self, func):
"""Called on `_NET_WM_ICON` chance
**Arguments**
* ``window.Window`` of client with changed icon
"""
return self._subscribe("net_wm_icon_change", func)
def selection_notify(self, func):
"""Called on selection notify
**Arguments**
* name of the selection
* dictionary describing selection, containing ``owner`` and
``selection`` as keys
"""
return self._subscribe("selection_notify", func)
def selection_change(self, func):
"""Called on selection change
**Arguments**
* name of the selection
* dictionary describing selection, containing ``owner`` and
``selection`` as keys
"""
return self._subscribe("selection_change", func)
def screen_change(self, func):
"""Called when a screen is added or screen configuration is changed (via xrandr)
Common usage is simply to call ``qtile.cmd_restart()`` on each event
(to restart qtile when there is a new monitor):
**Arguments**
* qtile manager instance
* ``xproto.randr.ScreenChangeNotify`` event
Examples
--------
::
@libqtile.hook.subscribe.screen_change
def restart_on_randr(qtile, ev):
qtile.cmd_restart()
"""
return self._subscribe("screen_change", func)
def current_screen_change(self, func):
"""Called when the current screen (i.e. the screen with focus) changes
**Arguments**
None
"""
return self._subscribe("current_screen_change", func)
subscribe = Subscribe()
class Unsubscribe(Subscribe):
"""
This class mirrors subscribe, except the _subscribe member has been
overridden to removed calls from hooks.
"""
def _subscribe(self, event, func):
lst = subscriptions.setdefault(event, [])
try:
lst.remove(func)
except ValueError:
raise utils.QtileError(
"Tried to unsubscribe a hook that was not"
" currently subscribed"
)
unsubscribe = Unsubscribe()
def fire(event, *args, **kwargs):
if event not in subscribe.hooks:
raise utils.QtileError("Unknown event: %s" % event)
if event not in SKIPLOG:
logger.info("Internal event: %s(%s, %s)", event, args, kwargs)
for i in subscriptions.get(event, []):
try:
i(*args, **kwargs)
except:
logger.exception("Error in hook %s", event)
|