Added the ability to run wofi in a normal window
This commit is contained in:
parent
57ea0caf59
commit
d13b02703f
16
src/main.c
16
src/main.c
@ -56,6 +56,7 @@ static void print_usage(char** argv) {
|
|||||||
printf("\t\t-p\tPrompt to display\n");
|
printf("\t\t-p\tPrompt to display\n");
|
||||||
printf("--xoffset\t-x\tThe x offset\n");
|
printf("--xoffset\t-x\tThe x offset\n");
|
||||||
printf("--yoffset\t-y\tThe y offset\n");
|
printf("--yoffset\t-y\tThe y offset\n");
|
||||||
|
printf("--normal-window\t-n\tRender to a normal window\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,6 +232,12 @@ int main(int argc, char** argv) {
|
|||||||
.flag = NULL,
|
.flag = NULL,
|
||||||
.val = 'y'
|
.val = 'y'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "normal-window",
|
||||||
|
.has_arg = no_argument,
|
||||||
|
.flag = NULL,
|
||||||
|
.val = 'n'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = NULL,
|
.name = NULL,
|
||||||
.has_arg = 0,
|
.has_arg = 0,
|
||||||
@ -248,8 +255,9 @@ int main(int argc, char** argv) {
|
|||||||
char* height = NULL;
|
char* height = NULL;
|
||||||
char* x = NULL;
|
char* x = NULL;
|
||||||
char* y = NULL;
|
char* y = NULL;
|
||||||
|
char* normal_window = NULL;
|
||||||
char opt;
|
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) {
|
switch(opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
print_usage(argv);
|
print_usage(argv);
|
||||||
@ -292,6 +300,9 @@ int main(int argc, char** argv) {
|
|||||||
case 'y':
|
case 'y':
|
||||||
y = optarg;
|
y = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'n':
|
||||||
|
normal_window = "true";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,6 +391,9 @@ int main(int argc, char** argv) {
|
|||||||
if(y != NULL) {
|
if(y != NULL) {
|
||||||
map_put(config, "y", y);
|
map_put(config, "y", y);
|
||||||
}
|
}
|
||||||
|
if(normal_window != NULL) {
|
||||||
|
map_put(config, "normal_window", normal_window);
|
||||||
|
}
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
|
|
||||||
|
21
src/wofi.c
21
src/wofi.c
@ -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_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);
|
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) {
|
static void get_input(GtkSearchEntry* entry, gpointer data) {
|
||||||
@ -166,8 +161,18 @@ void wofi_init(struct map* config) {
|
|||||||
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 = strtol(config_get(config, "x", "-1"), NULL, 10);
|
||||||
y = strtol(config_get(config, "y", "-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* mode = map_get(config, "mode");
|
||||||
char* prompt = config_get(config, "prompt", mode);
|
char* prompt = config_get(config, "prompt", mode);
|
||||||
|
|
||||||
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
|
gtk_widget_realize(window);
|
||||||
|
gtk_widget_set_name(window, "window");
|
||||||
|
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();
|
GdkDisplay* disp = gdk_display_get_default();
|
||||||
struct wl_display* wl = gdk_wayland_display_get_wl_display(disp);
|
struct wl_display* wl = gdk_wayland_display_get_wl_display(disp);
|
||||||
struct wl_registry* registry = wl_display_get_registry(wl);
|
struct wl_registry* registry = wl_display_get_registry(wl);
|
||||||
@ -177,10 +182,6 @@ void wofi_init(struct map* config) {
|
|||||||
};
|
};
|
||||||
wl_registry_add_listener(registry, &listener, NULL);
|
wl_registry_add_listener(registry, &listener, NULL);
|
||||||
wl_display_roundtrip(wl);
|
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);
|
GdkWindow* gdk_win = gtk_widget_get_window(window);
|
||||||
gdk_wayland_window_set_use_custom_surface(gdk_win);
|
gdk_wayland_window_set_use_custom_surface(gdk_win);
|
||||||
struct wl_surface* wl_surface = gdk_wayland_window_get_wl_surface(gdk_win);
|
struct wl_surface* wl_surface = gdk_wayland_window_get_wl_surface(gdk_win);
|
||||||
@ -191,6 +192,7 @@ void wofi_init(struct map* config) {
|
|||||||
zwlr_layer_surface_v1_add_listener(surface, surface_listener, NULL);
|
zwlr_layer_surface_v1_add_listener(surface, surface_listener, NULL);
|
||||||
wl_surface_commit(wl_surface);
|
wl_surface_commit(wl_surface);
|
||||||
wl_display_roundtrip(wl);
|
wl_display_roundtrip(wl);
|
||||||
|
}
|
||||||
|
|
||||||
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
||||||
gtk_widget_set_name(box, "outer-box");
|
gtk_widget_set_name(box, "outer-box");
|
||||||
@ -227,4 +229,5 @@ void wofi_init(struct map* config) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
gtk_widget_grab_focus(entry);
|
gtk_widget_grab_focus(entry);
|
||||||
|
gtk_widget_show_all(window);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user