fixed screenshurrt mid-switch to dmenu

This commit is contained in:
Paul Wilde 2023-08-29 20:50:32 +01:00
parent aaa23d06fd
commit 0650f4c957
2 changed files with 22 additions and 45 deletions

View file

@ -29,10 +29,8 @@ type
sel_bg: string sel_bg: string
sel_fg: string sel_fg: string
extra_cmd: string extra_cmd: string
i3BarInput* = object Tool* = enum
button*: int ROFI = "rofi", DMENU = "dmenu"
x*: int
y*: int
const WM_TOOLS_DIR* = getHomeDir() & ".wm_tools/" const WM_TOOLS_DIR* = getHomeDir() & ".wm_tools/"
const WM_TOOLS_SYNC_DIR = getHomeDir() & "/Nextcloud/.wm_tools_sync/" const WM_TOOLS_SYNC_DIR = getHomeDir() & "/Nextcloud/.wm_tools_sync/"
@ -58,19 +56,17 @@ const primary* = yellow
const secondary* = red const secondary* = red
const alert* = "#bd2c40" const alert* = "#bd2c40"
const font = "Hermit-12" const font = "Hermit-12"
const WL_DMENU = "dmenu"
const WL_ROFI = "wofi --dmenu"
const MAX_LINES = 20 const MAX_LINES = 20
var loop* = false var loop* = false
var stoploop* = true var stoploop* = true
var tool* = "dmenu" var tool* = ROFI
var wrappurr* = false var wrappurr* = false
var run_command* = "" var run_command* = ""
var wayland* = false var wayland* = false
proc newInfo*(str: string = "Info"): Info = proc newInfo*(str: string = "Info"): Info =
var title = str var title = str
if tool == "rofi": if tool == ROFI:
title = title & " : " title = title & " : "
return Info( return Info(
title: title, title: title,
@ -84,29 +80,25 @@ proc newInfo*(str: string = "Info"): Info =
color: foreground, color: foreground,
) )
proc newMenuConfig(cmd: string = "dmenu"): Menu = proc newMenuConfig(cmd: Tool = ROFI): Menu =
var run = cmd var run = $cmd
if wayland and cmd == "dmenu":
run = WL_DMENU
var menu = Menu() var menu = Menu()
menu.command = run menu.command = run
if cmd == ROFI:
menu.command &= " -dmenu"
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: Tool = ROFI): Menu =
var run = cmd var run = cmd
if wayland and cmd == "rofi -dmenu":
run = WL_ROFI
var menu = newMenuConfig(run) 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: Tool = DMENU): Menu =
var run = cmd var run = cmd
if wayland and cmd == "dmenu":
run = WL_DMENU
var menu = newMenuConfig(run) var menu = newMenuConfig(run)
menu.bottom = "-b" menu.bottom = "-b"
menu.grabkb = "-f" menu.grabkb = "-f"
@ -119,12 +111,13 @@ proc newDmenuConfig(cmd: string = "dmenu"): Menu =
return menu return menu
proc newMenu(): Menu = proc newMenu(): Menu =
if wrappurr: #if wrappurr:
return newDmenuConfig(run_command) # return newDmenuConfig(run_command)
elif tool == "rofi": case tool:
return newRofiConfig() of ROFI:
elif tool == "dmenu": return newRofiConfig()
return newDmenuConfig() of DMENU:
return newDmenuConfig()
return newMenuConfig() return newMenuConfig()
proc debugLog*(str: string) = proc debugLog*(str: string) =
@ -151,15 +144,6 @@ proc XisRunning*(): bool =
return true return true
return false return false
proc parseInput*(): i3BarInput =
let input = readLineFromStdin("")
try:
let jsonNode = parseJson(input)
let i3input = to(jsonNode, i3BarInput)
return i3input
except:
return i3BarInput()
proc clearInput*(count: int = 1) = proc clearInput*(count: int = 1) =
for x in countup(1, count): for x in countup(1, count):
discard readLineFromStdin("") discard readLineFromStdin("")
@ -179,8 +163,8 @@ proc quote*(str: string): string =
# Put leading and ending quote marks in # Put leading and ending quote marks in
return " \"" & text & "\" " return " \"" & text & "\" "
# ^ Add a spaces ^ so the previous flag isn't touching # ^ Add a spaces ^ so the previous flag isn't touching
#
#
proc markup(str: string): string = proc markup(str: string): string =
var text = str var text = str
@ -255,7 +239,7 @@ proc getCurrentClipboardContent*(): string =
proc outputData*(data: Info, args: varargs[string]): string {.discardable.} = proc outputData*(data: Info, args: varargs[string]): string {.discardable.} =
var output = "" var output = ""
if tool == "dmenu": if tool == DMENU:
output = runMenu(data,args, dmenu = true) output = runMenu(data,args, dmenu = true)
elif loop: elif loop:
# mainly for i3bar/i3blocks compatible output # mainly for i3bar/i3blocks compatible output
@ -298,9 +282,9 @@ for idx, arg in args:
stoploop = false stoploop = false
of "dmenu": of "dmenu":
stoploop = true stoploop = true
tool = "dmenu" tool = DMENU
of "rofi": of "rofi":
stoploop = true stoploop = true
tool = "rofi" tool = ROFI

View file

@ -7,16 +7,13 @@ const DATE_FORMAT = "yyyyMMdd-hhmmss"
const FILENAME = "Screenshot-%d.png" const FILENAME = "Screenshot-%d.png"
const TEMP_DIR = "/tmp/" const TEMP_DIR = "/tmp/"
const SCREENSHOT_CMD = "maim -u %s --format png %f" const SCREENSHOT_CMD = "maim -u %s --format png %f"
const SCREENSHOT_CMD_WL = "grim %s %f"
var RUN_CMD = SCREENSHOT_CMD var RUN_CMD = SCREENSHOT_CMD
let DATE_STR = now().format(DATE_FORMAT) let DATE_STR = now().format(DATE_FORMAT)
# where %s is an extra flag or process, i.e. xdotool for getting active window # where %s is an extra flag or process, i.e. xdotool for getting active window
const ACTIVE_WINDOW_CMD = "-i $(xdotool getactivewindow)" const ACTIVE_WINDOW_CMD = "-i $(xdotool getactivewindow)"
const REGION_FLAG = "-s" const REGION_FLAG = "-s"
const REGION_FLAG_WL = "-g \"$(slurp)\""
var REGION_CMD = REGION_FLAG var REGION_CMD = REGION_FLAG
const CLIPBOARD_CMD = "xclip -selection clipboard -t image/png" const CLIPBOARD_CMD = "xclip -selection clipboard -t image/png"
const CLIPBOARD_CMD_WL = "wl-copy"
var CLIP_CMD = CLIPBOARD_CMD var CLIP_CMD = CLIPBOARD_CMD
proc saveToClipboard(filename: string) = proc saveToClipboard(filename: string) =
@ -88,10 +85,6 @@ proc takeScreenshot() =
return return
if isMainModule: if isMainModule:
if wayland:
RUN_CMD = SCREENSHOT_CMD_WL
REGION_CMD = REGION_FLAG_WL
CLIP_CMD = CLIPBOARD_CMD_WL
for arg in args: for arg in args:
if arg in TYPES: if arg in TYPES:
screenshot_type = arg screenshot_type = arg