BeastModeAllDay

config.py

Dec 15th, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.15 KB | None | 0 0
  1. import os, subprocess
  2.  
  3. import libqtile
  4. import libqtile.config
  5. import libqtile.command
  6. import libqtile
  7.  
  8. from libqtile import *
  9. from libqtile.config import *
  10. from libqtile.command import *
  11.  
  12. from libqtile import hook, layout
  13. from libqtile.config import Key, Screen, Group, Drag, Click
  14. from libqtile.command import lazy
  15. from libqtile import layout, bar, widget, extension
  16.  
  17. import copy
  18.  
  19. import subprocess
  20. from time import time
  21. from pathlib import Path
  22.  
  23.  
  24. # ----------------------------
  25. # -------- Colors ------------
  26. # ----------------------------
  27.  
  28. COLS = {
  29. "dark_0": "#1d2021",
  30. "dark_1": "#282828",
  31. "dark_2": "#32302f",
  32. "dark_3": "#3c3836",
  33. "dark_4": "#504945",
  34. "dark_5": "#665c54",
  35. "dark_6": "#7c6f64",
  36. "gray_0": "#928374",
  37. "light_0": "#f9f5d7",
  38. "light_1": "#fbf1c7",
  39. "light_2": "#f2e5bc",
  40. "light_3": "#ebdbb2",
  41. "light_4": "#d5c4a1",
  42. "light_5": "#bdae93",
  43. "light_6": "#a89984",
  44. "red_0": "#fb4934",
  45. "red_1": "#cc241d",
  46. "red_2": "#9d0006",
  47. "green_0": "#b8bb26",
  48. "green_1": "#98971a",
  49. "green_2": "#79740e",
  50. "yellow_0": "#fabd2f",
  51. "yellow_1": "#d79921",
  52. "yellow_2": "#b57614",
  53. "blue_0": "#83a598",
  54. "blue_1": "#458588",
  55. "blue_2": "#076678",
  56. "purple_0": "#d3869b",
  57. "purple_1": "#b16286",
  58. "purple_2": "#8f3f71",
  59. "aqua_0": "#8ec07c",
  60. "aqua_1": "#689d6a",
  61. "aqua_2": "#427b58",
  62. "orange_0": "#fe8019",
  63. "orange_1": "#d65d0e",
  64. "orange_2": "#af3a03",
  65. # Additional related colors from the deus colorscheme
  66. 'deus_1': '#2C323B',
  67. 'deus_2': '#646D7A',
  68. 'deus_3': '#48505D',
  69. 'deus_4': '#1A222F',
  70. 'deus_5': '#101A28',
  71. }
  72.  
  73. BG_COLOR = "#000000"
  74. FG_COLOR = "#FFFFFF"
  75. ALERT_COLOR="#FF0000"
  76.  
  77. GROUP_URGENT_BORDER = ALERT_COLOR
  78. GROUP_FG = BG_COLOR
  79. GROUP_INACTIVE_FG = "#888888"
  80. GROUP_ACTIVE_FG=GROUP_FG
  81. GROUP_SELECTED_BG="#bbbbbb"
  82. GROUP_BG = FG_COLOR
  83. GROUP_OTHER_BORDER='#00004F'
  84. GROUP_THIS_BORDER="#0000FF"
  85. FONT_SIZE=18
  86. #ICON_SIZE=30
  87. #ICON_PADDING=-10
  88.  
  89. # ----------------------------
  90. # ----- Workspace Box --------
  91. # ----------------------------
  92.  
  93. def group_as_workspace(g):
  94. cloned = copy.copy(g)
  95. cloned.label = cloned.name[1:2]
  96. return cloned
  97.  
  98. class WorkspaceBox(widget.GroupBox):
  99. def __init__(self, **config):
  100. widget.GroupBox.__init__(self, **config)
  101.  
  102. @property
  103. def groups(self):
  104. """
  105. returns list of visible groups.
  106. The existing groups are filtered by the visible_groups attribute and
  107. their label. Groups with an empty string as label are never contained.
  108. Groups that are not named in visible_groups are not returned.
  109. """
  110. if super().groups:
  111. return list(map(group_as_workspace, super().groups))
  112. #return list(map(lambda g: Group(g.name), super().groups))
  113. else:
  114. return super().groups
  115.  
  116. # ----------------------------
  117. # ------ Screen Shots --------
  118. # ----------------------------
  119.  
  120. # ----------------------------
  121. # -------- Hotkeys -----------
  122. # ----------------------------
  123.  
  124.  
  125. mod = "mod4"
  126. alt = "mod1"
  127. keys = [
  128.  
  129. # Layout hotkeys
  130. Key([mod], "minus", lazy.layout.shrink_main()),
  131. Key([mod], "plus", lazy.layout.grow_main()),
  132. Key([alt, "shift"], "Tab", lazy.layout.up()),
  133. Key([alt], "Tab", lazy.layout.down()),
  134. Key([mod, "shift"], "Tab", lazy.prev_layout()),
  135. Key([mod], "Tab", lazy.next_layout()),
  136. Key([mod], "n", lazy.layout.normalize()),
  137. Key([mod], "o", lazy.layout.maximize()),
  138. #Key([mod], "grave", lazy.screen.toggle_group()),
  139. #Key([mod], "plus", lazy.layout.increase_ratio()),
  140. #Key([mod], "minus", lazy.layout.decrease_ratio()),
  141.  
  142. Key([mod], "Down", lazy.layout.down()),
  143. Key([mod], "Up", lazy.layout.up()),
  144. Key([mod], "Left", lazy.layout.left()),
  145. Key([mod], "Right", lazy.layout.right()),
  146. Key([mod, alt], "Down", lazy.layout.shuffle_down()),
  147. Key([mod, alt], "Up", lazy.layout.shuffle_up()),
  148. Key([mod, alt], "Left", lazy.layout.shuffle_left()),
  149. Key([mod, alt], "Right", lazy.layout.shuffle_right()),
  150. Key([mod, "shift"], "Down", lazy.layout.flip_down()),
  151. Key([mod, "shift"], "Up", lazy.layout.flip_up()),
  152. Key([mod, "shift"], "Left", lazy.layout.flip_left()),
  153. Key([mod, "shift"], "Right", lazy.layout.flip_right()),
  154. Key([mod, "control"], "Down", lazy.layout.grow_down()),
  155. Key([mod, "control"], "Up", lazy.layout.grow_up()),
  156. Key([mod, "control"], "Left", lazy.layout.grow_left()),
  157. Key([mod, "control"], "Right", lazy.layout.grow_right()),
  158. Key([mod, "control"], "n", lazy.layout.normalize()),
  159. Key([mod], "space", lazy.layout.toggle_split()),
  160.  
  161. # Window hotkeys
  162. Key([mod], "f", lazy.window.toggle_fullscreen()), #default
  163. Key([mod, "shift"], "f", lazy.window.toggle_floating()), #default
  164. Key([mod, "shift"], "k", lazy.window.kill()),
  165.  
  166. # Spec hotkeys
  167. Key([mod], "Return", lazy.spawncmd()),
  168.  
  169. # Apps hotkeys
  170. Key([mod], "t", lazy.spawn("terminator")),
  171. Key([mod], "w", lazy.spawn("google-chrome-stable")),
  172. Key([mod], "c", lazy.spawn("terminator -e \"nano -w ~/.config/qtile/config.py\"")),
  173.  
  174. # System hotkeys
  175. Key([], "Print", lazy.spawn("scrot -e 'mv $f /home/user/screenshots/'")),
  176. Key([mod, "shift", "control"], "h", lazy.spawn("systemctl hibernate")),
  177. Key([mod, "shift", "control"], "r", lazy.restart()),
  178. Key([mod, "shift", "control"], "q", lazy.shutdown()),
  179. Key([mod], "u", lazy.spawn("terminator -e \"yay -Syu --devel && read -p \\\"Press enter to continue\\\"\"")),
  180. Key([mod, "shift"], "u", lazy.spawn("terminator -e \"yay -yuYc --devel --gendb && read -p \\\"Press enter to continue\\\"\"")),
  181.  
  182. # Media hotkeys
  183. Key([], 'XF86AudioMute', lazy.spawn('amixer -q set Master toggle')),
  184. Key([], 'XF86AudioLowerVolume', lazy.spawn('amixer -c 0 sset Master 1- unmute')),
  185. Key([], 'XF86AudioRaiseVolume', lazy.spawn('amixer -c 0 sset Master 1+ unmute')),
  186.  
  187. #dmenu
  188. Key([mod], 'm', lazy.spawn('xfce4-appfinder')),
  189. #Key([mod], 'm', lazy.spawn('dmenu_run -i -b -p ">>>" -fn "Open Sans-10" -nb "#000" -nf "#fff" -sb "#00BF32" -sf "#fff"')),
  190. #Key([mod], 'm', lazy.run_extension(extension.J4DmenuDesktop()))
  191.  
  192. # screenshots
  193. Key([], 'Print', lazy.function(screenshot())),
  194. Key([mod], 'Print', lazy.spawn('deepin-screenshot'))
  195. ]
  196.  
  197. # ----------------------------
  198. # --- Workspaces and Rooms ---
  199. # ----------------------------
  200.  
  201. # The basic idea behind Workspaces and Rooms is to control
  202. # DIFFERENT subsets of groups with the SAME hotkeys.
  203. # So we can have multiple 'qwerasdf' rooms in a different workspaces.
  204. #
  205. # Qtile Groups are used behind the scenes, but their visibility
  206. # is set dynamically.
  207.  
  208. def get_group_name(workspace, room):
  209. """ Calculate Group name based on (workspace,room) combination.
  210. """
  211. return "%s%s" % (room, workspace)
  212.  
  213. # List of available workspaces.
  214. # Each workspace has its own prefix and hotkey.
  215. workspaces = [
  216. (fa.icons['window-restore'], 'F1'),
  217. (fa.icons['chrome'], 'F2'),
  218. (fa.icons['code'], 'F3'),
  219. (fa.icons['comments'], 'F4'),
  220. ]
  221.  
  222. # List of available rooms.
  223. # Rooms are identical between workspaces, but they can
  224. # be changed to different ones as well. Minor changes required.
  225. rooms = "1234567890"
  226.  
  227. # Oops, time for a little hack there.
  228. # This is a global object with information about current workspace.
  229. # (viable as config code, not sure about client-server though)
  230. wsp = {
  231. 'current': workspaces[0][0], # first workspace is active by default
  232. }
  233. # ... and information about active group in the each workspace.
  234. for w, _ in workspaces:
  235. wsp[w] = {
  236. 'active_group': get_group_name(w, rooms[0]) # first room is active by default
  237. }
  238.  
  239. def get_workspace_groups(workspace):
  240. """ Get list of Groups that belongs to workspace.
  241. """
  242. return [ get_group_name(workspace, room) for room in rooms]
  243.  
  244. def get_room_groups(room):
  245. """ Get list of Groups that belongs to room.
  246. """
  247. return [ get_group_name(w, room) for w,_ in workspaces]
  248.  
  249. def to_workspace(workspace):
  250. """ Change current workspace to another one.
  251. """
  252. def f(qtile):
  253. global wsp
  254.  
  255. # we need to save current active room(group) somewhere
  256. # to return to it later
  257. wsp[wsp['current']]['active_group'] = qtile.currentGroup.name
  258.  
  259. # now we can change current workspace to the new one
  260. # (no actual switch there)
  261. wsp['current'] = workspace
  262. # and navigate to the active group from the workspace
  263. # (actual switch)
  264. qtile.groupMap[
  265. wsp[workspace]['active_group']
  266. ].cmd_toscreen()
  267.  
  268. # we also need to change subset of visible groups in the GroupBox widget
  269. qtile.widgetMap['groupbox'].visible_groups=get_workspace_groups(workspace)
  270. qtile.widgetMap['groupbox'].draw()
  271. qtile.widgetMap['workspacebox'].visible_groups=get_room_groups(wsp[workspace]['active_group'][:1])
  272. qtile.widgetMap['workspacebox'].draw()
  273. # You can do some other cosmetic stuff here.
  274. # For example, change Bar background depending on the current workspace.
  275. # # qtile.widgetMap['groupbox'].bar.background="ff0000"
  276. return f
  277.  
  278. def to_room(room):
  279. """ Change active room to another within the current workspace.
  280. """
  281. def f(qtile):
  282. global wsp
  283. qtile.widgetMap['workspacebox'].visible_groups=get_room_groups(room)
  284. qtile.widgetMap['workspacebox'].draw()
  285. qtile.groupMap[get_group_name(wsp['current'], room)].cmd_toscreen()
  286. return f
  287.  
  288. def window_to_workspace(workspace, room=rooms[0]):
  289. """ Move active window to another workspace.
  290. """
  291. def f(qtile):
  292. global wsp
  293. qtile.currentWindow.togroup(wsp[workspace]['active_group'])
  294. return f
  295.  
  296. def window_to_room(room):
  297. """ Move active window to another room within the current workspace.
  298. """
  299. def f(qtile):
  300. global wsp
  301. qtile.currentWindow.togroup(get_group_name(wsp['current'], room))
  302. return f
  303.  
  304. # Create individual Group for each (workspace,room) combination we have
  305. groups = []
  306. for workspace, hotkey in workspaces:
  307. for room in rooms:
  308. groups.append(Group(get_group_name(workspace, room), label=room))
  309.  
  310. # Assign individual hotkeys for each workspace we have
  311. for workspace, hotkey in workspaces:
  312. keys.append(Key([mod], hotkey, lazy.function(
  313. to_workspace(workspace))))
  314. keys.append(Key([mod, "shift"], hotkey, lazy.function(
  315. window_to_workspace(workspace))))
  316.  
  317. # Assign shared hotkeys for each room we have.
  318. # Decision about actual group to open is made dynamically.
  319. for room in rooms:
  320. keys.append(Key([mod], room, lazy.function(
  321. to_room(room))))
  322. keys.append(Key([mod, "shift"], room, lazy.function(
  323. window_to_room(room))))
  324.  
  325.  
  326. # ---------------------------
  327. # ---- Layouts & Widgets ----
  328. # ---------------------------
  329.  
  330. GAP_SIZE=15
  331.  
  332. layouts = [
  333. layout.Bsp(margin=GAP_SIZE),
  334. layout.MonadTall(margin=GAP_SIZE),
  335. layout.MonadWide(margin=GAP_SIZE),
  336. layout.Max(),
  337. layout.Stack(margin=GAP_SIZE),
  338. layout.Columns(margin=GAP_SIZE),
  339. layout.VerticalTile(margin=GAP_SIZE),
  340. layout.TreeTab(panel_width=200),
  341. ]
  342.  
  343. widget_defaults = dict(
  344. font='Arial',
  345. fontsize=12,
  346. padding=3,
  347. )
  348.  
  349. screens = [
  350. Screen(
  351. top=bar.Bar(
  352. [
  353. widget.TextBox(
  354. font="Arial",
  355. foreground=GROUP_BG,
  356. text=" ?",
  357. fontsize=(FONT_SIZE*5.25),
  358. padding=-1
  359. ),
  360. WorkspaceBox(
  361. visible_groups=get_room_groups("1"),
  362. spacing=0,
  363. font="font-awesome",
  364.  
  365. other_current_screen_border=GROUP_OTHER_BORDER,
  366. this_current_screen_border=GROUP_THIS_BORDER,
  367. other_screen_border=GROUP_OTHER_BORDER,
  368. this_screen_border=GROUP_THIS_BORDER,
  369. highlight_color=GROUP_SELECTED_BG,
  370. urgent_border=GROUP_URGENT_BORDER,
  371. background=GROUP_BG,
  372. highlight_method="line",
  373. inactive=GROUP_INACTIVE_FG,
  374. active=GROUP_ACTIVE_FG,
  375. disable_drag=True,
  376. borderwidth=4,
  377. fontsize=FONT_SIZE,
  378. foreground=GROUP_FG
  379. ),
  380. widget.TextBox(
  381. font="font-awesome",
  382. foreground=GROUP_FG,
  383. background=GROUP_BG,
  384. text=("?"),
  385. fontsize=FONT_SIZE,
  386. padding=15
  387. ),
  388. widget.GroupBox(
  389. visible_groups=get_workspace_groups(wsp['current']),
  390. spacing=0,
  391. font="font-awesome",
  392. #padding=-1,
  393. background=GROUP_BG,
  394. other_current_screen_border=GROUP_OTHER_BORDER,
  395. this_current_screen_border=GROUP_THIS_BORDER,
  396. other_screen_border=GROUP_OTHER_BORDER,
  397. this_screen_border=GROUP_THIS_BORDER,
  398. highlight_color=GROUP_SELECTED_BG,
  399. urgent_border=GROUP_URGENT_BORDER,
  400. highlight_method="line",
  401. inactive=GROUP_INACTIVE_FG,
  402. active=GROUP_ACTIVE_FG,
  403. disable_drag=True,
  404. borderwidth=4,
  405. fontsize=FONT_SIZE,
  406. foreground=GROUP_INACTIVE_FG
  407. ),
  408. widget.TextBox(
  409. font="Arial",
  410. foreground=GROUP_BG,
  411. text="? ",
  412. fontsize=(FONT_SIZE*5.25),
  413. padding=-20
  414. ),
  415. widget.Prompt(
  416. prompt="run: ",
  417. ignore_dups_history=True,
  418. fontsize=FONT_SIZE
  419. ),
  420. widget.WindowName(
  421. fontsize=FONT_SIZE
  422. ),
  423. widget.Spacer(
  424. length=50
  425. ),
  426. widget.TextBox(
  427. font="font-awesome",
  428. text=("?"),
  429. fontsize=FONT_SIZE,
  430. padding=0
  431. ),
  432. widget.Spacer(
  433. length=10
  434. ),
  435. widget.Mpris2(
  436. background=BG_COLOR,
  437. foreground=FG_COLOR,
  438. name='spotify',
  439. stop_pause_text='?',
  440. fontsize=FONT_SIZE,
  441. scroll_chars=None,
  442. display_metadata=['xesam:title', 'xesam:artist'],
  443. objname="org.mpris.MediaPlayer2.spotify",
  444. ),
  445. widget.Spacer(
  446. length=75
  447. ),
  448. widget.TextBox(
  449. font="font-awesome",
  450. text=("?"),
  451. fontsize=FONT_SIZE,
  452. padding=0
  453. ),
  454. widget.NetGraph(
  455. bandwidth_type="up",
  456. type="linefill",
  457. line_width=1
  458. ),
  459. widget.Spacer(
  460. length=10
  461. ),
  462. widget.TextBox(
  463. font="font-awesome",
  464. text=("?"),
  465. fontsize=FONT_SIZE,
  466. padding=0
  467. ),
  468. widget.NetGraph(
  469. bandwidth_type="down",
  470. type="linefill",
  471. line_width=1
  472. ),
  473. widget.Spacer(
  474. length=10
  475. ),
  476. widget.TextBox(
  477. font="font-awesome",
  478. text=("?"),
  479. fontsize=FONT_SIZE,
  480. padding=0
  481. ),
  482. widget.CPUGraph(
  483. type="linefill",
  484. line_width=1
  485. ),
  486. widget.Spacer(
  487. length=10
  488. ),
  489. widget.TextBox(
  490. font="font-awesome",
  491. text=("?"),
  492. fontsize=FONT_SIZE,
  493. padding=0
  494. ),
  495. widget.MemoryGraph(
  496. type="linefill",
  497. line_width=1
  498. ),
  499. widget.Spacer(
  500. length=10
  501. ),
  502. widget.TextBox(
  503. font="font-awesome",
  504. text=("?"),
  505. fontsize=FONT_SIZE,
  506. padding=0
  507. ),
  508. widget.HDDBusyGraph(
  509. device="nvme0n1",
  510. type="linefill",
  511. line_width=1
  512. ),
  513. widget.Spacer(
  514. length=10
  515. ),
  516. widget.TextBox(
  517. font="font-awesome",
  518. text=("?"),
  519. fontsize=FONT_SIZE,
  520. padding=0
  521. ),
  522. widget.ThermalSensor(
  523. fontsize=FONT_SIZE,
  524. ),
  525. widget.Spacer(
  526. length=100
  527. ),
  528. widget.CheckUpdates(
  529. fontsize=FONT_SIZE,
  530. display_format="? {updates}",
  531. font="font-logos",
  532. colour_have_updates=ALERT_COLOR,
  533. #padding=15
  534. ),
  535. widget.Spacer(
  536. length=10
  537. ),
  538. widget.Sep(),
  539. widget.Spacer(
  540. length=10
  541. ),
  542. widget.TextBox(
  543. font="font-awesome",
  544. text=("?"),
  545. fontsize=FONT_SIZE,
  546. padding=0
  547. ),
  548. widget.Spacer(
  549. length=5
  550. ),
  551. widget.Volume(
  552. fontsize=FONT_SIZE,
  553. update_interval=2
  554. ),
  555. widget.Spacer(
  556. length=10
  557. ),
  558. widget.Sep(),
  559. widget.Spacer(
  560. length=10
  561. ),
  562. widget.TextBox(
  563. font="font-awesome",
  564. text=("?"),
  565. fontsize=FONT_SIZE,
  566. padding=0
  567. ),
  568. widget.Spacer(
  569. length=5
  570. ),
  571. widget.DF(
  572. fontsize=FONT_SIZE,
  573. warn_space=5,
  574. visible_on_warn=False,
  575. warn_color=ALERT_COLOR,
  576. ),
  577. widget.Spacer(
  578. length=50
  579. ),
  580. widget.Systray(
  581. #icon_size=ICON_SIZE,
  582. #padding=ICON_PADDING
  583. ),
  584. widget.Spacer(
  585. length=10
  586. ),
  587. widget.Clock(
  588. fontsize=FONT_SIZE,
  589. format='%a %b %d, %H:%M',
  590. ),
  591. widget.CurrentLayoutIcon(scale=0.65),
  592. widget.CurrentLayout(
  593. fontsize=FONT_SIZE,
  594. ),
  595. ],
  596. (FONT_SIZE*2),
  597. opacity=0.75
  598. ),
  599. )
  600. ]
  601.  
  602. mouse = [
  603. Click([mod, "shift"], "Button1", lazy.window.toggle_floating()),
  604. Drag([mod], "Button1", lazy.window.set_position_floating(), start=lazy.window.get_position()),
  605. Drag([mod, alt], "Button1", lazy.window.set_size_floating(), start=lazy.window.get_size()),
  606. Click([mod, "control"], "Button1", lazy.window.bring_to_front())
  607. ]
  608.  
  609. floating_layout = layout.floating.Floating(
  610. auto_float_types=(
  611. 'notification',
  612. 'toolbar',
  613. 'splash',
  614. 'dialog',
  615. ),
  616. float_rules=[{'wmclass': x} for x in (
  617. 'audacious',
  618. 'Download'
  619. 'file_progress',
  620. 'file-roller',
  621. 'gimp',
  622. 'Transmission',
  623. 'Update',
  624. 'Xephyr',
  625. 'xfce4-appfinder',
  626. )]
  627. )
  628.  
  629. dgroups_key_binder = None
  630. dgroups_app_rules = []
  631. main = None
  632. follow_mouse_focus = True
  633. bring_front_click = False
  634. cursor_warp = False
  635. auto_fullscreen = True
  636. focus_on_window_activation = "smart"
  637. extentions = []
  638. wmname = "LG3D"
  639.  
  640. @hook.subscribe.startup_once
  641. def autostart():
  642. home = os.path.expanduser('~/.config/qtile/autostart.sh')
  643. subprocess.call([home])
Advertisement
Add Comment
Please, Sign In to add comment