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

View file

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