Added --location and made -x and -y behave as proper offsets as they do in rofi
This commit is contained in:
parent
ff8572fc0d
commit
8bcdfc0f13
16
src/main.c
16
src/main.c
@ -72,6 +72,7 @@ static void print_usage(char** argv) {
|
|||||||
printf("--insensitive\t-i\tAllows case insensitive searching\n");
|
printf("--insensitive\t-i\tAllows case insensitive searching\n");
|
||||||
printf("--parse-search\t-q\tParses the search text removing image escapes and pango\n");
|
printf("--parse-search\t-q\tParses the search text removing image escapes and pango\n");
|
||||||
printf("--version\t-v\tPrints the version and then exits\n");
|
printf("--version\t-v\tPrints the version and then exits\n");
|
||||||
|
printf("--location\t-l\tSets the location\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,6 +326,12 @@ int main(int argc, char** argv) {
|
|||||||
.flag = NULL,
|
.flag = NULL,
|
||||||
.val = 'v'
|
.val = 'v'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "location",
|
||||||
|
.has_arg = required_argument,
|
||||||
|
.flag = NULL,
|
||||||
|
.val = 'l'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = NULL,
|
.name = NULL,
|
||||||
.has_arg = 0,
|
.has_arg = 0,
|
||||||
@ -353,8 +360,9 @@ int main(int argc, char** argv) {
|
|||||||
char* matching = NULL;
|
char* matching = NULL;
|
||||||
char* insensitive = NULL;
|
char* insensitive = NULL;
|
||||||
char* parse_search = NULL;
|
char* parse_search = NULL;
|
||||||
|
char* location = NULL;
|
||||||
int opt;
|
int opt;
|
||||||
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:iqv", opts, NULL)) != -1) {
|
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:iqvl:", opts, NULL)) != -1) {
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
print_usage(argv);
|
print_usage(argv);
|
||||||
@ -434,6 +442,9 @@ int main(int argc, char** argv) {
|
|||||||
printf(VERSION"\n");
|
printf(VERSION"\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
location = optarg;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,6 +590,9 @@ int main(int argc, char** argv) {
|
|||||||
if(parse_search != NULL) {
|
if(parse_search != NULL) {
|
||||||
map_put(config, "parse_search", parse_search);
|
map_put(config, "parse_search", parse_search);
|
||||||
}
|
}
|
||||||
|
if(location != NULL) {
|
||||||
|
map_put(config, "location", location);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
|
71
src/wofi.c
71
src/wofi.c
@ -24,8 +24,20 @@ enum matching_mode {
|
|||||||
MATCHING_MODE_FUZZY
|
MATCHING_MODE_FUZZY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum locations {
|
||||||
|
LOCATION_CENTER,
|
||||||
|
LOCATION_TOP_LEFT,
|
||||||
|
LOCATION_TOP,
|
||||||
|
LOCATION_TOP_RIGHT,
|
||||||
|
LOCATION_RIGHT,
|
||||||
|
LOCATION_BOTTOM_RIGHT,
|
||||||
|
LOCATION_BOTTOM,
|
||||||
|
LOCATION_BOTTOM_LEFT,
|
||||||
|
LOCATION_LEFT
|
||||||
|
};
|
||||||
|
|
||||||
static uint64_t width, height;
|
static uint64_t width, height;
|
||||||
static int64_t x, y;
|
static char* x, *y;
|
||||||
static struct zwlr_layer_shell_v1* shell;
|
static struct zwlr_layer_shell_v1* shell;
|
||||||
static GtkWidget* window, *outer_box, *scroll, *entry, *inner_box, *previous_selection = NULL;
|
static GtkWidget* window, *outer_box, *scroll, *entry, *inner_box, *previous_selection = NULL;
|
||||||
static const gchar* filter;
|
static const gchar* filter;
|
||||||
@ -47,6 +59,7 @@ static bool insensitive;
|
|||||||
static bool parse_search;
|
static bool parse_search;
|
||||||
static uint8_t content_halign;
|
static uint8_t content_halign;
|
||||||
static struct map* config;
|
static struct map* config;
|
||||||
|
static enum locations location;
|
||||||
|
|
||||||
struct node {
|
struct node {
|
||||||
size_t action_count;
|
size_t action_count;
|
||||||
@ -73,9 +86,54 @@ static void config_surface(void* data, struct zwlr_layer_surface_v1* surface, ui
|
|||||||
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
||||||
zwlr_layer_surface_v1_set_size(surface, width, height);
|
zwlr_layer_surface_v1_set_size(surface, width, height);
|
||||||
zwlr_layer_surface_v1_set_keyboard_interactivity(surface, true);
|
zwlr_layer_surface_v1_set_keyboard_interactivity(surface, true);
|
||||||
if(x >= 0 && y >= 0) {
|
|
||||||
zwlr_layer_surface_v1_set_margin(surface, y, 0, 0, x);
|
if(location > 8) {
|
||||||
zwlr_layer_surface_v1_set_anchor(surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
|
location -= 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(x != NULL || y != NULL) {
|
||||||
|
int64_t ix = x == NULL ? 0 : strtol(x, NULL, 10);
|
||||||
|
int64_t iy = y == NULL ? 0 : strtol(y, NULL, 10);
|
||||||
|
|
||||||
|
if(location == LOCATION_CENTER) {
|
||||||
|
location = LOCATION_TOP_LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
zwlr_layer_surface_v1_set_margin(surface, iy, -ix, -iy, ix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(location > 0) {
|
||||||
|
enum zwlr_layer_surface_v1_anchor anchor;
|
||||||
|
|
||||||
|
switch(location) {
|
||||||
|
case LOCATION_CENTER:
|
||||||
|
break;
|
||||||
|
case LOCATION_TOP_LEFT:
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
|
||||||
|
break;
|
||||||
|
case LOCATION_TOP:
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
|
||||||
|
break;
|
||||||
|
case LOCATION_TOP_RIGHT:
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||||
|
break;
|
||||||
|
case LOCATION_LEFT:
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
|
||||||
|
break;
|
||||||
|
case LOCATION_RIGHT:
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||||
|
break;
|
||||||
|
case LOCATION_BOTTOM_LEFT:
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
|
||||||
|
break;
|
||||||
|
case LOCATION_BOTTOM:
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
||||||
|
break;
|
||||||
|
case LOCATION_BOTTOM_RIGHT:
|
||||||
|
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
zwlr_layer_surface_v1_set_anchor(surface, anchor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,8 +811,8 @@ void wofi_init(struct map* _config) {
|
|||||||
config = _config;
|
config = _config;
|
||||||
width = strtol(config_get(config, "width", "1000"), NULL, 10);
|
width = strtol(config_get(config, "width", "1000"), NULL, 10);
|
||||||
height = strtol(config_get(config, "height", "400"), NULL, 10);
|
height = strtol(config_get(config, "height", "400"), NULL, 10);
|
||||||
x = strtol(config_get(config, "x", "-1"), NULL, 10);
|
x = map_get(config, "x");
|
||||||
y = strtol(config_get(config, "y", "-1"), NULL, 10);
|
y = map_get(config, "y");
|
||||||
bool normal_window = strcmp(config_get(config, "normal_window", "false"), "true") == 0;
|
bool normal_window = strcmp(config_get(config, "normal_window", "false"), "true") == 0;
|
||||||
mode = map_get(config, "mode");
|
mode = map_get(config, "mode");
|
||||||
uint8_t orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "vertical", "horizontal");
|
uint8_t orientation = config_get_mnemonic(config, "orientation", "vertical", 2, "vertical", "horizontal");
|
||||||
@ -781,6 +839,7 @@ void wofi_init(struct map* _config) {
|
|||||||
matching = config_get_mnemonic(config, "matching", "contains", 2, "contains", "fuzzy");
|
matching = config_get_mnemonic(config, "matching", "contains", 2, "contains", "fuzzy");
|
||||||
insensitive = strcmp(config_get(config, "insensitive", "false"), "true") == 0;
|
insensitive = strcmp(config_get(config, "insensitive", "false"), "true") == 0;
|
||||||
parse_search = strcmp(config_get(config, "parse_search", "false"), "true") == 0;
|
parse_search = strcmp(config_get(config, "parse_search", "false"), "true") == 0;
|
||||||
|
location = config_get_mnemonic(config, "location", "center", 18, "center", "top_left", "top", "top_right", "right", "bottom_right", "bottom", "bottom_left", "left", "0", "1", "2", "3", "4", "5", "6", "7", "8");
|
||||||
modes = map_init_void();
|
modes = map_init_void();
|
||||||
|
|
||||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
|
Loading…
Reference in New Issue
Block a user