~tardypad/dotfiles

bb16fb1575b2e0b743c5d0921e7289e28774acc1 — Damien Tardy-Panis 9 months ago c70d2bb
Add presentation mode to disable notifications
M files/configs/i3blocks/config => files/configs/i3blocks/config +3 -0
@@ 23,6 23,9 @@ signal=4

[chat]

[presentation]
signal=10

[microphone]
signal=7


M files/configs/sway/config.d/bindings => files/configs/sway/config.d/bindings +3 -0
@@ 40,6 40,9 @@ bindsym $mod+{key/i} exec sway-toggle-window-idle-inhibitor visible \
# toggle night mode
bindsym --locked $mod+{key/t} exec night-mode toggle

# toggle presentation mode
bindsym $mod+Ctrl+{key/p} exec presentation toggle


## notifications


M files/docs/i3blocks/Makefile => files/docs/i3blocks/Makefile +1 -0
@@ 13,6 13,7 @@ i3blocks-docs:
	$(setup_file)/docs/i3blocks/i3blocks-night-mode.scd     | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/i3blocks-night-mode.1perso
	$(setup_file)/docs/i3blocks/i3blocks-pomodoro.scd       | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/i3blocks-pomodoro.1perso
	$(setup_file)/docs/i3blocks/i3blocks-power.scd          | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/i3blocks-power.1perso
	$(setup_file)/docs/i3blocks/i3blocks-presentation.scd   | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/i3blocks-presentation.1perso
	$(setup_file)/docs/i3blocks/i3blocks-time-tracker.scd   | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/i3blocks-time-tracker.1perso
	$(setup_file)/docs/i3blocks/i3blocks-volume.scd         | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/i3blocks-volume.1perso
	$(setup_file)/docs/i3blocks/i3blocks-webcam.scd         | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/i3blocks-webcam.1perso

A files/docs/i3blocks/i3blocks-presentation.scd => files/docs/i3blocks/i3blocks-presentation.scd +33 -0
@@ 0,0 1,33 @@
i3blocks-presentation(1perso)

# NAME

i3blocks-presentation - Report the presentation status for i3blocks

# SYNOPSIS

i3blocks-presentation

# DESCRIPTION

Print the presentation status for i3blocks

# OPTIONS

None

# OPERANDS

None

# ENVIRONMENT VARIABLES

None

# FILES

None

# DEPENDENCIES

- presentation

M files/docs/shell/Makefile => files/docs/shell/Makefile +1 -0
@@ 34,6 34,7 @@ shell-docs:
	$(setup_file)/docs/shell/play-somafm.scd              | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/play-somafm.1perso
	$(setup_file)/docs/shell/plot.scd                     | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/plot.1perso
	$(setup_file)/docs/shell/pomodoro.scd                 | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/pomodoro.1perso
	$(setup_file)/docs/shell/presentation.scd             | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/presentation.1perso
	$(setup_file)/docs/shell/project-path.scd             | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/project-path.1perso
	$(setup_file)/docs/shell/query-hosts-tags.scd         | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/query-hosts-tags.1perso
	$(setup_file)/docs/shell/read-news.scd                | scdoc > $(DESTDIR)$(DATA_DIR)/man/man1/read-news.1perso

M files/docs/shell/notify.scd => files/docs/shell/notify.scd +1 -0
@@ 46,3 46,4 @@ _$XDG_RUNTIME_DIR/notification_\*_
# DEPENDENCIES

- gdbus
- presentation

A files/docs/shell/presentation.scd => files/docs/shell/presentation.scd +47 -0
@@ 0,0 1,47 @@
presentation(1perso)

# NAME

presentation - Manage "presentation" mode

# SYNOPSIS

presentation [ *status* | *enable* | *disable* | *toggle* ]

# DESCRIPTION

Manage "presentation" mode.

# OPTIONS

None

# OPERANDS

*status*
	Display whether the "presentation" mode is "enabled" or "disabled"++
This is the default action if none is specified

*disable*
	Disable "presentation" mode

*enable*
	Enable "presentation" mode

*toggle*
	Toggle "presentation" mode

# ENVIRONMENT VARIABLES

_XDG_RUNTIME_DIR_
	Path to user-specific base directory to store runtime files++
If unset, defaults to /tmp

# FILES

_$XDG_RUNTIME_DIR/presentation_
	File used as a flag to store the status of the mode

# DEPENDENCIES

- pkill

M files/scripts/i3blocks/Makefile => files/scripts/i3blocks/Makefile +2 -0
@@ 13,6 13,7 @@ i3blocks-scripts:
	$(setup_file)/scripts/i3blocks/i3blocks-night-mode     > $(DESTDIR)$(BIN_DIR)/i3blocks-night-mode
	$(setup_file)/scripts/i3blocks/i3blocks-pomodoro       > $(DESTDIR)$(BIN_DIR)/i3blocks-pomodoro
	$(setup_file)/scripts/i3blocks/i3blocks-power          > $(DESTDIR)$(BIN_DIR)/i3blocks-power
	$(setup_file)/scripts/i3blocks/i3blocks-presentation   > $(DESTDIR)$(BIN_DIR)/i3blocks-presentation
	$(setup_file)/scripts/i3blocks/i3blocks-time-tracker   > $(DESTDIR)$(BIN_DIR)/i3blocks-time-tracker
	$(setup_file)/scripts/i3blocks/i3blocks-volume         > $(DESTDIR)$(BIN_DIR)/i3blocks-volume
	$(setup_file)/scripts/i3blocks/i3blocks-webcam         > $(DESTDIR)$(BIN_DIR)/i3blocks-webcam


@@ 27,6 28,7 @@ i3blocks-scripts:
	chmod +x $(DESTDIR)$(BIN_DIR)/i3blocks-night-mode
	chmod +x $(DESTDIR)$(BIN_DIR)/i3blocks-pomodoro
	chmod +x $(DESTDIR)$(BIN_DIR)/i3blocks-power
	chmod +x $(DESTDIR)$(BIN_DIR)/i3blocks-presentation
	chmod +x $(DESTDIR)$(BIN_DIR)/i3blocks-time-tracker
	chmod +x $(DESTDIR)$(BIN_DIR)/i3blocks-volume
	chmod +x $(DESTDIR)$(BIN_DIR)/i3blocks-webcam

A files/scripts/i3blocks/i3blocks-presentation => files/scripts/i3blocks/i3blocks-presentation +8 -0
@@ 0,0 1,8 @@
#!/bin/sh

[ "$( presentation status )" = 'enabled' ] || exit 0

COLOR='#{color/notice/hex}'
TEXT=''

printf '%s\n\n%s\n' "${TEXT}" "${COLOR}"

M files/scripts/shell/Makefile => files/scripts/shell/Makefile +2 -0
@@ 34,6 34,7 @@ shell-scripts:
	$(setup_file)/scripts/shell/play-somafm                  > $(DESTDIR)$(BIN_DIR)/play-somafm
	$(setup_file)/scripts/shell/plot                         > $(DESTDIR)$(BIN_DIR)/plot
	$(setup_file)/scripts/shell/pomodoro                     > $(DESTDIR)$(BIN_DIR)/pomodoro
	$(setup_file)/scripts/shell/presentation                 > $(DESTDIR)$(BIN_DIR)/presentation
	$(setup_file)/scripts/shell/project-path                 > $(DESTDIR)$(BIN_DIR)/project-path
	$(setup_file)/scripts/shell/query-hosts-tags             > $(DESTDIR)$(BIN_DIR)/query-hosts-tags
	$(setup_file)/scripts/shell/read-news                    > $(DESTDIR)$(BIN_DIR)/read-news


@@ 81,6 82,7 @@ shell-scripts:
	chmod +x $(DESTDIR)$(BIN_DIR)/play-somafm
	chmod +x $(DESTDIR)$(BIN_DIR)/plot
	chmod +x $(DESTDIR)$(BIN_DIR)/pomodoro
	chmod +x $(DESTDIR)$(BIN_DIR)/presentation
	chmod +x $(DESTDIR)$(BIN_DIR)/project-path
	chmod +x $(DESTDIR)$(BIN_DIR)/query-hosts-tags
	chmod +x $(DESTDIR)$(BIN_DIR)/read-news

M files/scripts/shell/notify => files/scripts/shell/notify +2 -0
@@ 86,4 86,6 @@ init_variables
parse_command_line "$@"
validate_command_line

[ "$( presentation status )" = 'disabled' ] || exit 0

send_notification

A files/scripts/shell/presentation => files/scripts/shell/presentation +67 -0
@@ 0,0 1,67 @@
#!/bin/sh

init_variables() {
  COMMAND=${0##*/}

  FILE_PATH="${XDG_RUNTIME_DIR:-/tmp}/presentation"

  ACTION='status'
}

parse_command_line() {
  [ -z "$1" ] || ACTION="$1"
}

validate_command_line() {
  if [ "${ACTION}" != 'enable' ] \
     && [ "${ACTION}" != 'disable' ] \
     && [ "${ACTION}" != 'toggle' ] \
     && [ "${ACTION}" != 'status' ]; then
    exit_error "Invalid action '${ACTION}'"
  fi
}

exit_error() {
  [ -z "$1" ] || echo "${COMMAND}: $1"
  exit 1
} >&2

pres_enable() {
  touch "${FILE_PATH}" \
    && update_i3blocks
}

pres_disable() {
  rm -f "${FILE_PATH}" \
    && update_i3blocks
}

update_i3blocks() {
  pkill -x -RTMIN+10 i3blocks
}

pres_status() {
  if is_pres_enabled; then
    echo 'enabled'
  else
    echo 'disabled'
  fi
}

pres_toggle() {
  if is_pres_enabled; then
    pres_disable
  else
    pres_enable
  fi
}

is_pres_enabled() {
  [ -f "${FILE_PATH}" ]
}

init_variables
parse_command_line "$@"
validate_command_line

"pres_${ACTION}"