summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c115
-rw-r--r--src/main.c5
-rw-r--r--src/tofi.h2
3 files changed, 97 insertions, 25 deletions
diff --git a/src/config.c b/src/config.c
index 59b8012..a1bfb7a 100644
--- a/src/config.c
+++ b/src/config.c
@@ -21,6 +21,50 @@
/* Anyone with a 10M config file is doing something very wrong */
#define MAX_CONFIG_SIZE (10*1024*1024)
+/* Convenience macros for anchor combinations */
+#define ANCHOR_TOP_LEFT (\
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT \
+ )
+#define ANCHOR_TOP (\
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT \
+ )
+#define ANCHOR_TOP_RIGHT (\
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT \
+ )
+#define ANCHOR_RIGHT (\
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM \
+ )
+#define ANCHOR_BOTTOM_RIGHT (\
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT \
+ )
+#define ANCHOR_BOTTOM (\
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT \
+ )
+#define ANCHOR_BOTTOM_LEFT (\
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT \
+ )
+#define ANCHOR_LEFT (\
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM \
+ )
+#define ANCHOR_CENTER (\
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT \
+ | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT \
+ )
+
struct uint32_percent {
uint32_t value;
bool percent;
@@ -308,6 +352,14 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const
tofi->window.entry.selection_background_padding = parse_int32(filename, lineno, value, &err);
} else if (strcasecmp(option, "selection-background") == 0) {
tofi->window.entry.selection_background_color = parse_color(filename, lineno, value, &err);
+ } else if (strcasecmp(option, "exclusive-zone") == 0) {
+ if (strcmp(value, "-1") == 0) {
+ tofi->window.exclusive_zone = -1;
+ } else {
+ percent = parse_uint32_percent(filename, lineno, value, &err);
+ tofi->window.exclusive_zone = percent.value;
+ tofi->window.exclusive_zone_is_percent = percent.percent;
+ }
} else if (strcasecmp(option, "width") == 0) {
percent = parse_uint32_percent(filename, lineno, value, &err);
tofi->window.width = percent.value;
@@ -489,6 +541,36 @@ void config_fixup_values(struct tofi *tofi)
tofi->window.entry.padding_right_is_percent,
tofi->window.scale,
tofi->use_scale);
+
+ /* Exclusive zone base depends on anchor. */
+ switch (tofi->anchor) {
+ case ANCHOR_TOP:
+ case ANCHOR_BOTTOM:
+ tofi->window.exclusive_zone = fixup_percentage(
+ tofi->window.exclusive_zone,
+ tofi->output_height,
+ tofi->window.exclusive_zone_is_percent,
+ tofi->window.scale,
+ tofi->use_scale);
+ break;
+ case ANCHOR_LEFT:
+ case ANCHOR_RIGHT:
+ tofi->window.exclusive_zone = fixup_percentage(
+ tofi->window.exclusive_zone,
+ tofi->output_width,
+ tofi->window.exclusive_zone_is_percent,
+ tofi->window.scale,
+ tofi->use_scale);
+ break;
+ default:
+ /*
+ * Exclusive zone >0 is meaningless for other anchor
+ * positions.
+ */
+ tofi->window.exclusive_zone =
+ MIN(tofi->window.exclusive_zone, 0);
+ break;
+ }
}
char *get_config_path()
@@ -544,46 +626,31 @@ wchar_t parse_wchar(const char *filename, size_t lineno, const char *str, bool *
uint32_t parse_anchor(const char *filename, size_t lineno, const char *str, bool *err)
{
if(strcasecmp(str, "top-left") == 0) {
- return ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
+ return ANCHOR_TOP_LEFT;
}
if (strcasecmp(str, "top") == 0) {
- return ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
+ return ANCHOR_TOP;
}
if (strcasecmp(str, "top-right") == 0) {
- return ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
+ return ANCHOR_TOP_RIGHT;
}
if (strcasecmp(str, "right") == 0) {
- return ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
+ return ANCHOR_RIGHT;
}
if (strcasecmp(str, "bottom-right") == 0) {
- return ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
+ return ANCHOR_BOTTOM_RIGHT;
}
if (strcasecmp(str, "bottom") == 0) {
- return ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
+ return ANCHOR_BOTTOM;
}
if (strcasecmp(str, "bottom-left") == 0) {
- return ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
+ return ANCHOR_BOTTOM_LEFT;
}
if (strcasecmp(str, "left") == 0) {
- return ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
+ return ANCHOR_LEFT;
}
if (strcasecmp(str, "center") == 0) {
- return ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
- | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
+ return ANCHOR_CENTER;
}
PARSE_ERROR(filename, lineno, "Invalid anchor \"%s\".\n", str);
*err = true;
diff --git a/src/main.c b/src/main.c
index 9c14cda..212211d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -816,6 +816,7 @@ static void usage()
" --output <name> Name of output to display window on.\n"
" --scale <true|false> Follow the output's scale factor.\n"
" --anchor <position> Location on screen to anchor window.\n"
+" --exclusive-zone <-1|px|%> Exclusive zone size, or -1 for none.\n"
" --margin-top <px|%> Offset from top of screen.\n"
" --margin-bottom <px|%> Offset from bottom of screen.\n"
" --margin-left <px|%> Offset from left of screen.\n"
@@ -848,6 +849,7 @@ const struct option long_options[] = {
{"config", required_argument, NULL, 'c'},
{"include", required_argument, NULL, 0},
{"anchor", required_argument, NULL, 0},
+ {"exclusive-zone", required_argument, NULL, 0},
{"background-color", required_argument, NULL, 0},
{"corner-radius", required_argument, NULL, 0},
{"font", required_argument, NULL, 0},
@@ -1022,6 +1024,7 @@ int main(int argc, char *argv[])
.scale = 1,
.width = 1280,
.height = 720,
+ .exclusive_zone = -1,
.entry = {
.font_name = "Sans",
.font_size = 24,
@@ -1321,7 +1324,7 @@ int main(int argc, char *argv[])
tofi.anchor);
zwlr_layer_surface_v1_set_exclusive_zone(
tofi.window.zwlr_layer_surface,
- -1);
+ tofi.window.exclusive_zone);
zwlr_layer_surface_v1_set_size(
tofi.window.zwlr_layer_surface,
tofi.window.width / tofi.window.scale,
diff --git a/src/tofi.h b/src/tofi.h
index 419f86e..be3e821 100644
--- a/src/tofi.h
+++ b/src/tofi.h
@@ -56,12 +56,14 @@ struct tofi {
uint32_t height;
uint32_t scale;
int32_t transform;
+ int32_t exclusive_zone;
int32_t margin_top;
int32_t margin_bottom;
int32_t margin_left;
int32_t margin_right;
bool width_is_percent;
bool height_is_percent;
+ bool exclusive_zone_is_percent;
bool margin_top_is_percent;
bool margin_bottom_is_percent;
bool margin_left_is_percent;