Added the ability to run wofi in a normal window

This commit is contained in:
Scoopta 2019-08-17 19:22:09 -07:00
parent 57ea0caf59
commit d13b02703f
2 changed files with 42 additions and 25 deletions

View File

@ -56,6 +56,7 @@ static void print_usage(char** argv) {
printf("\t\t-p\tPrompt to display\n");
printf("--xoffset\t-x\tThe x offset\n");
printf("--yoffset\t-y\tThe y offset\n");
printf("--normal-window\t-n\tRender to a normal window\n");
exit(0);
}
@ -231,6 +232,12 @@ int main(int argc, char** argv) {
.flag = NULL,
.val = 'y'
},
{
.name = "normal-window",
.has_arg = no_argument,
.flag = NULL,
.val = 'n'
},
{
.name = NULL,
.has_arg = 0,
@ -248,8 +255,9 @@ int main(int argc, char** argv) {
char* height = NULL;
char* x = NULL;
char* y = NULL;
char* normal_window = NULL;
char opt;
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:", opts, NULL)) != -1) {
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:n", opts, NULL)) != -1) {
switch(opt) {
case 'h':
print_usage(argv);
@ -292,6 +300,9 @@ int main(int argc, char** argv) {
case 'y':
y = optarg;
break;
case 'n':
normal_window = "true";
break;
}
}
@ -380,6 +391,9 @@ int main(int argc, char** argv) {
if(y != NULL) {
map_put(config, "y", y);
}
if(normal_window != NULL) {
map_put(config, "normal_window", normal_window);
}
gtk_init(&argc, &argv);

View File

@ -43,11 +43,6 @@ static void config_surface(void* data, struct zwlr_layer_surface_v1* surface, ui
zwlr_layer_surface_v1_set_margin(surface, y, 0, 0, x);
zwlr_layer_surface_v1_set_anchor(surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
}
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
gtk_window_resize(GTK_WINDOW(window), width, height);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
gtk_widget_show_all(window);
}
static void get_input(GtkSearchEntry* entry, gpointer data) {
@ -166,31 +161,38 @@ void wofi_init(struct map* config) {
height = strtol(config_get(config, "height", "400"), NULL, 10);
x = strtol(config_get(config, "x", "-1"), NULL, 10);
y = strtol(config_get(config, "y", "-1"), NULL, 10);
bool normal_window = strcmp(config_get(config, "normal_window", "false"), "true") == 0;
char* mode = map_get(config, "mode");
char* prompt = config_get(config, "prompt", mode);
GdkDisplay* disp = gdk_display_get_default();
struct wl_display* wl = gdk_wayland_display_get_wl_display(disp);
struct wl_registry* registry = wl_display_get_registry(wl);
struct wl_registry_listener listener = {
.global = add_interface,
.global_remove = nop
};
wl_registry_add_listener(registry, &listener, NULL);
wl_display_roundtrip(wl);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_realize(window);
gtk_widget_set_name(window, "window");
GdkWindow* gdk_win = gtk_widget_get_window(window);
gdk_wayland_window_set_use_custom_surface(gdk_win);
struct wl_surface* wl_surface = gdk_wayland_window_get_wl_surface(gdk_win);
struct zwlr_layer_surface_v1* surface = zwlr_layer_shell_v1_get_layer_surface(shell, wl_surface, NULL, ZWLR_LAYER_SHELL_V1_LAYER_TOP, "wofi");
struct zwlr_layer_surface_v1_listener* surface_listener = malloc(sizeof(struct zwlr_layer_surface_v1_listener));
surface_listener->configure = config_surface;
surface_listener->closed = nop;
zwlr_layer_surface_v1_add_listener(surface, surface_listener, NULL);
wl_surface_commit(wl_surface);
wl_display_roundtrip(wl);
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
gtk_window_resize(GTK_WINDOW(window), width, height);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
if(!normal_window) {
GdkDisplay* disp = gdk_display_get_default();
struct wl_display* wl = gdk_wayland_display_get_wl_display(disp);
struct wl_registry* registry = wl_display_get_registry(wl);
struct wl_registry_listener listener = {
.global = add_interface,
.global_remove = nop
};
wl_registry_add_listener(registry, &listener, NULL);
wl_display_roundtrip(wl);
GdkWindow* gdk_win = gtk_widget_get_window(window);
gdk_wayland_window_set_use_custom_surface(gdk_win);
struct wl_surface* wl_surface = gdk_wayland_window_get_wl_surface(gdk_win);
struct zwlr_layer_surface_v1* surface = zwlr_layer_shell_v1_get_layer_surface(shell, wl_surface, NULL, ZWLR_LAYER_SHELL_V1_LAYER_TOP, "wofi");
struct zwlr_layer_surface_v1_listener* surface_listener = malloc(sizeof(struct zwlr_layer_surface_v1_listener));
surface_listener->configure = config_surface;
surface_listener->closed = nop;
zwlr_layer_surface_v1_add_listener(surface, surface_listener, NULL);
wl_surface_commit(wl_surface);
wl_display_roundtrip(wl);
}
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_name(box, "outer-box");
@ -227,4 +229,5 @@ void wofi_init(struct map* config) {
exit(1);
}
gtk_widget_grab_focus(entry);
gtk_widget_show_all(window);
}