checked for wayland use without the need for -w parameter

This commit is contained in:
Paul Wilde 2022-07-15 21:16:18 +01:00
parent 9aba9e1faf
commit a51af62d78
3 changed files with 31 additions and 13 deletions

View file

@ -57,12 +57,15 @@ const secondary* = red
const alert* = "#bd2c40" const alert* = "#bd2c40"
const MAX_LINES = 20 const MAX_LINES = 20
const font = "Hermit-12" const font = "Hermit-12"
const WL_DMENU = "dmenu"
const WL_ROFI = "wofi --dmenu"
var loop* = false var loop* = false
var stoploop* = true var stoploop* = true
var tool* = "dmenu" var tool* = "dmenu"
var passmenu* = false var passmenu* = false
var command_wrapper* = false var command_wrapper* = false
var run_command* = "" var run_command* = ""
var wayland* = false
proc newInfo*(str: string = "Info"): Info = proc newInfo*(str: string = "Info"): Info =
var title = str var title = str
@ -81,20 +84,29 @@ proc newInfo*(str: string = "Info"): Info =
) )
proc newMenuConfig(cmd: string = "dmenu"): Menu = proc newMenuConfig(cmd: string = "dmenu"): Menu =
var run = cmd
if wayland and cmd == "dmenu":
run = WL_DMENU
var menu = Menu() var menu = Menu()
menu.command = cmd menu.command = run
menu.prompt = "-p" menu.prompt = "-p"
menu.i_case = "-i" menu.i_case = "-i"
menu.lines_shown = "-l" menu.lines_shown = "-l"
return menu return menu
proc newRofiConfig(cmd: string = "rofi -dmenu"): Menu = proc newRofiConfig(cmd: string = "rofi -dmenu"): Menu =
var menu = newMenuConfig(cmd) var run = cmd
if wayland and cmd == "rofi -dmenu":
run = WL_ROFI
var menu = newMenuConfig(run)
menu.extra_cmd = "-markup-rows -kb-row-select \"Tab\" -kb-row-tab \"\"" menu.extra_cmd = "-markup-rows -kb-row-select \"Tab\" -kb-row-tab \"\""
return menu return menu
proc newDmenuConfig(cmd: string = "dmenu"): Menu = proc newDmenuConfig(cmd: string = "dmenu"): Menu =
var menu = newMenuConfig(cmd) var run = cmd
if wayland and cmd == "dmenu":
run = WL_DMENU
var menu = newMenuConfig(run)
menu.bottom = "-b" menu.bottom = "-b"
menu.grabkb = "-f" menu.grabkb = "-f"
menu.monitor = "-m" menu.monitor = "-m"
@ -125,6 +137,11 @@ proc switchTwmMode*(mode: string = "default") =
# I intend to add support for more twm as time goes on (I switch around a lot) # I intend to add support for more twm as time goes on (I switch around a lot)
# Switch out of an i3 bindsym mode if set # Switch out of an i3 bindsym mode if set
discard execCmd("i3-msg mode \"" & mode & "\"") discard execCmd("i3-msg mode \"" & mode & "\"")
discard execCmd("sway mode \"" & mode & "\"")
proc checkWayland() =
if getEnv("XDG_SESSION_TYPE") == "wayland":
wayland = true
proc parseInput*(): i3BarInput = proc parseInput*(): i3BarInput =
let input = readLineFromStdin("") let input = readLineFromStdin("")
@ -223,6 +240,8 @@ proc outputData*(data: Info, args: varargs[string]): string {.discardable.} =
# Switch bindsym mode back to default as it could be being used. # Switch bindsym mode back to default as it could be being used.
switchTwmMode() switchTwmMode()
checkWayland()
let args* = getArguments() let args* = getArguments()
for idx, arg in args: for idx, arg in args:
case arg: case arg:

View file

@ -99,13 +99,13 @@ proc main() =
if isMainModule: if isMainModule:
block start: block start:
for arg in args: if wayland:
case arg:
of "-w":
CMD = BACKLIGHT_CMD_WL CMD = BACKLIGHT_CMD_WL
UP = UP_WL UP = UP_WL
DOWN = DOWN_WL DOWN = DOWN_WL
SET = SET_WL SET = SET_WL
for arg in args:
case arg:
of "up": of "up":
brightnessUp() brightnessUp()
break start break start

View file

@ -2,7 +2,6 @@ import base
import std/[times,os,osproc,strutils,sequtils] import std/[times,os,osproc,strutils,sequtils]
var screenshot_type = "" var screenshot_type = ""
var wayland = false
const TYPES = @["region", "fullscreen", "window"] const TYPES = @["region", "fullscreen", "window"]
const DATE_FORMAT = "yyyyMMdd-hhmmss" const DATE_FORMAT = "yyyyMMdd-hhmmss"
const FILENAME = "Screenshot-%d.png" const FILENAME = "Screenshot-%d.png"
@ -89,11 +88,11 @@ proc takeScreenshot() =
return return
if isMainModule: if isMainModule:
for arg in args: if wayland:
if arg == "-w":
RUN_CMD = SCREENSHOT_CMD_WL RUN_CMD = SCREENSHOT_CMD_WL
REGION_CMD = REGION_FLAG_WL REGION_CMD = REGION_FLAG_WL
CLIP_CMD = CLIPBOARD_CMD_WL CLIP_CMD = CLIPBOARD_CMD_WL
for arg in args:
if arg in TYPES: if arg in TYPES:
screenshot_type = arg screenshot_type = arg
break break