chvol

Simple interface to set PulseAudio's volume, with graphical feedback! 🔊

Commit
72726143596128665cc2a19555a40b6a8fb081bb
Parent
e66ed4bdeed76da576a024fd8500a674f46b9ecb
Author
Pablo <pablo-pie@riseup.net>
Date

Made the window y offset configurable

Diffstats

4 files changed, 13 insertions, 7 deletions

Status Name Changes Insertions Deletions
Modified chvol.conf 2 files changed 1 0
Modified nob.c 2 files changed 1 0
Modified src/configure.c 2 files changed 10 4
Modified src/main.c 2 files changed 1 3
diff --git a/chvol.conf b/chvol.conf
@@ -2,6 +2,7 @@
 width           = 350
 height          = 60
 progress_height = 5
+y               = 15
 padding         = 20
 border          = 2
 timeout_ms      = 1500
diff --git a/nob.c b/nob.c
@@ -51,6 +51,7 @@ i32 main(i32 argc, char** argv)
   }
 
   srcs.count = 0;
+  da_append(&srcs, CONFIG_PATH);
   assert(walk_dir(ASSETS_DIR, append_all_srcs, .data = &srcs));
   needs_build |= needs_rebuild(OUTPUT_PATH, srcs.items, srcs.count);
 
diff --git a/src/configure.c b/src/configure.c
@@ -31,6 +31,7 @@ typedef struct {
   i64 window_width;
   i64 window_height;
   i64 window_progress_height;
+  i64 window_y;
   i64 window_padding;
   i64 window_border;
   i64 window_timeout_ms;
@@ -75,6 +76,7 @@ i32 main(i32 argc, char** argv)
   fprintf(f, "#define WIN_WIDTH           %ld\n",   config.window_width);
   fprintf(f, "#define WIN_HEIGHT          %ld\n",   config.window_height);
   fprintf(f, "#define WIN_PROGRESS_HEIGHT %ld\n",   config.window_progress_height);
+  fprintf(f, "#define WIN_Y               %ld\n",   config.window_y);
   fprintf(f, "#define WIN_PADDING         %ld\n",   config.window_padding);
   fprintf(f, "#define WIN_BORDER          %ld\n",   config.window_border);
   fprintf(f, "#define WIN_TIMEOUT_MS      %ld\n\n", config.window_timeout_ms);
@@ -660,11 +662,12 @@ b8 lexer_next(Lexer* l, Token* token)
 }
 
 // = parser for our config format =============================================
-static_assert(sizeof(Config) == 104);
+static_assert(sizeof(Config) == 112);
 typedef enum {
   KEY_WINDOW_WIDTH = 0,
   KEY_WINDOW_HEIGHT,
   KEY_WINDOW_PROGRESS_HEIGHT,
+  KEY_WINDOW_Y,
   KEY_WINDOW_PADDING,
   KEY_WINDOW_BORDER,
   KEY_WINDOW_TIMEOUT_MS,
@@ -689,11 +692,12 @@ typedef struct {
   u64       max_val;
 } KeyInfo;
 
-static_assert(KEY_COUNT == 13);
+static_assert(KEY_COUNT == 14);
 KeyInfo key_infos[KEY_COUNT] = {
   [KEY_WINDOW_WIDTH]           = { "width",            "window", offsetof(Config, window_width),           TOKEN_INT, },
   [KEY_WINDOW_HEIGHT]          = { "height",           "window", offsetof(Config, window_height),          TOKEN_INT, },
   [KEY_WINDOW_PROGRESS_HEIGHT] = { "progress_height",  "window", offsetof(Config, window_progress_height), TOKEN_INT, },
+  [KEY_WINDOW_Y]               = { "y",                "window", offsetof(Config, window_y),               TOKEN_INT, },
   [KEY_WINDOW_PADDING]         = { "padding",          "window", offsetof(Config, window_padding),         TOKEN_INT, },
   [KEY_WINDOW_BORDER]          = { "border",           "window", offsetof(Config, window_border),          TOKEN_INT, },
   [KEY_WINDOW_TIMEOUT_MS]      = { "timeout_ms",       "window", offsetof(Config, window_timeout_ms),      TOKEN_INT, },
@@ -738,6 +742,7 @@ b8 parse_config(const char* path, Config* config)
   if (!lexer_new(path, &l, &str_store)) return false;
 
   // = parsing ================================================================
+  static_assert(KEY_COUNT <= 16);
   Token token; u16 key_set_flag = 0;
   while (!lexer_finished(&l)) {
     if (!lexer_next(&l, &token))     return false;
@@ -806,8 +811,9 @@ b8 parse_config(const char* path, Config* config)
     }
   }
 
-  if (!check_bounds(path, KEY_WINDOW_WIDTH,  config, 1, 0)) return false;
-  if (!check_bounds(path, KEY_WINDOW_HEIGHT, config, 1, 0)) return false;
+  if (!check_bounds(path, KEY_WINDOW_WIDTH,  config, 1, 0))   return false;
+  if (!check_bounds(path, KEY_WINDOW_HEIGHT, config, 1, 0))   return false;
+  if (!check_bounds(path, KEY_WINDOW_Y,      config, 0, 100)) return false;
 
   i64 size = config->window_width;
   if (config->window_height > size) size = config->window_height;
diff --git a/src/main.c b/src/main.c
@@ -20,8 +20,6 @@
 #include "ints.h"
 #include "config.h"
 
-//static_assert(VOLUME_CAP <= U8_MAX);
-
 typedef enum {
   CMD_VOL_GET = 0,
   CMD_VOL_SET,
@@ -226,7 +224,7 @@ void x11_launch_window(u8 percent, u32 timeout_ms)
 
   // ==========================================================================
   i32 x_offset = (screen_width  - WIN_WIDTH )/2;
-  i32 y_offset = (screen_height - WIN_HEIGHT)/2;
+  i32 y_offset = screen_height*(100 - WIN_Y)/100 - WIN_HEIGHT/2;
   Window win   = XCreateWindow(
     d, root, x_offset, y_offset, WIN_WIDTH, WIN_HEIGHT, 0,
     depth, InputOutput,