-
Notifications
You must be signed in to change notification settings - Fork 13
/
x-tile
executable file
·121 lines (114 loc) · 4.03 KB
/
x-tile
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
#!/usr/bin/env python3
#
# x-tile
#
# Copyright 2009-2020
# Giuseppe Penone <[email protected]>,
# Chris Camacho (chris_c) <[email protected]>.
#
# plus many thanks to http://tronche.com/gui/x/xlib/
# and http://tripie.sweb.cz/utils/wmctrl/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import sys
import os
import gettext
import ctypes
import ctypes.util
import locale
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import builtins
if os.path.isfile('modules/globs.py'): MODULES_PATH = 'modules/'
else: MODULES_PATH = '/usr/share/x-tile/modules/'
sys.path.append(MODULES_PATH)
import cons
import core
import globs
# language installation
gconf_client = core.MockingGConf()
gconf_client.add_dir(cons.GCONF_DIR)
lang_str = gconf_client.get_string(cons.GCONF_LANG)
if lang_str == None:
gconf_client.set_string(cons.GCONF_LANG, "default")
lang_str = "default"
if lang_str != "default": os.environ["LANGUAGE"] = lang_str
try:
locale.bindtextdomain(cons.APP_NAME, cons.LOCALE_PATH)
gettext.translation(cons.APP_NAME, cons.LOCALE_PATH).install()
except:
def _(transl_str):
return transl_str
builtins._ = _
builtins.glob = globs.GlobalsObject()
try:
libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library("libc"))
libc.prctl(15, cons.APP_NAME, 0, 0, 0)
except: print("libc.prctl not available, the process name will be python and not x-tile")
if len(sys.argv) < 2: sys.argv.append("w")
arg = sys.argv[1]
if arg == "w":
x = core.XTile(core.InfoModel())
x.launch_application()
x.reload_windows_list()
Gtk.main()
elif arg in ("-V", "--version"):
print("X Tile {}".format(cons.VERSION))
elif arg in cons.CMD_LINE_ACTIONS:
x = core.XTile(core.InfoModel())
x.launch_application()
x.cmd_line_only = True
if arg not in ["z", "i", "y"]:
x.reload_windows_list()
x.flag_all_rows()
if arg == "z": x.undo_tiling()
elif arg == "i": x.invert_tiling()
elif arg == "y": x.cycle_tiling()
elif arg == "v": x.tile_vertically()
elif arg == "h": x.tile_horizontally()
elif arg == "u": x.tile_triangle_up()
elif arg == "d": x.tile_triangle_down()
elif arg == "l": x.tile_triangle_left()
elif arg == "r": x.tile_triangle_right()
elif arg == "q": x.tile_quad()
elif arg == "g":
wins = len(x.store.get_checked_windows_list(True)[0])
if wins == 1:
x.maximize_checked_windows()
elif wins:
try:
rows, cols = ([max(0, min(wins, int(a))) for a in sys.argv[2:4]] + [0, 0])[:2]
except:
print("bad arguments")
exit(1)
if not rows and not cols:
for rows, cols in ((r, c) for r in range(1, 100) for c in [r, r + 1]):
if rows * cols >= wins:
break
elif not rows:
rows = (wins + cols - 1) // cols
elif not cols:
cols = (wins + rows - 1) // rows
cons.GRID_ROWS, cons.GRID_COLS = rows, cols
x.tile_grid()
elif arg == "1": x.tile_custom_1_run()
elif arg == "2": x.tile_custom_2_run()
elif arg == "m": x.maximize_checked_windows()
elif arg == "M": x.unmaximize_checked_windows()
elif arg == "c": x.close_checked_windows()
else: # -h
print(cons.HELP_TEXT)