/usr/share/cinnamon-screensaver/util/focusNavigator.py is in cinnamon-screensaver 3.6.1-2.
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 | #!/usr/bin/python3
# coding: utf-8
from gi.repository import Gtk
import status
class FocusNavigator:
"""
FocusNavigator helps with tab navigation between
widgets in our status.focusWidgets list.
Since we handle most user events ourselves, we also
need to handle Tab events correctly.
"""
def __init__(self, widgets=[]):
status.focusWidgets = widgets
def _get_focus_index(self):
widgets = status.focusWidgets
focus_index = -1
for widget in widgets:
if widget.has_focus():
focus_index = widgets.index(widget)
break
return focus_index
def _focus_first_possible(self):
widgets = status.focusWidgets
for widget in widgets:
if widget.get_sensitive():
widget.grab_focus()
widget.grab_default()
break
def _focus_next(self, current):
widgets = status.focusWidgets
new = current + 1
if new >= len(widgets):
new = 0
if not widgets[new].get_sensitive():
self._focus_next(new)
return
widgets[new].grab_focus()
widgets[new].grab_default()
def _focus_previous(self, current):
widgets = status.focusWidgets
new = current - 1
if new < 0:
new = len(widgets) - 1
if not widgets[new].get_sensitive():
self._focus_previous(new)
return
widgets[new].grab_focus()
widgets[new].grab_default()
def navigate(self, reverse):
current_index = self._get_focus_index()
if current_index == -1:
self._focus_first_possible()
if reverse:
self._focus_previous(current_index)
else:
self._focus_next(current_index)
def activate_focus(self):
widgets = status.focusWidgets
focus_index = self._get_focus_index()
if focus_index == -1:
return
widget = widgets[focus_index]
if isinstance(widget, Gtk.Button):
widget.clicked()
elif isinstance(widget, Gtk.Entry):
widget.activate()
def get_focused_widget(self):
widgets = status.focusWidgets
focus_index = self._get_focus_index()
if focus_index == -1:
return None
return widgets[focus_index]
|