commit e25cc5924f5dcd6af1478af8122c3ba814474e9b Author: Kljunas2 Date: Wed Apr 27 14:13:32 2022 +0200 initial commit Signed-off-by: Kljunas2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba077a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0ee386c --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,26 @@ +The MIT License (MIT) +===================== + +Copyright © `<2022>` `` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..24fff41 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +CC = gcc +RM = rm +BINARY = activate-linux +CFLAGS = $(shell pkg-config --cflags --libs gtk+-3.0 gtk-layer-shell-0) + +activate-linux: + $(CC) src/activate_linux.c -o bin/$(BINARY) $(CFLAGS) + +.PHONY: clean +clean: + $(RM) -rf bin/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..124d837 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# activate-linux for Wayland +The "Activate Windows" watermark ported to Linux with Gtk Layer Shell + +# Linux + +## Dependencies +This project depends on: +- `gtk-3.0` +- `gtk-layer-shell` + +## Building +``` +make +``` diff --git a/src/activate_linux.c b/src/activate_linux.c new file mode 100644 index 0000000..69b0b89 --- /dev/null +++ b/src/activate_linux.c @@ -0,0 +1,73 @@ +#include +#include +#include + +struct config { + char *title; + char *subtitle; +}; + +void draw_window(GdkMonitor *monitor, char *text, GtkApplication *app) { + GtkWindow *gtk_window = GTK_WINDOW(gtk_application_window_new(app)); + + gtk_layer_init_for_window(gtk_window); + + gtk_layer_set_layer(gtk_window, GTK_LAYER_SHELL_LAYER_TOP); + // + // gtk layer shell options + gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, 40); + gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, 40); + static const gboolean anchors[] = {FALSE, TRUE, FALSE, TRUE}; + for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) { + gtk_layer_set_anchor (gtk_window, i, anchors[i]); + } + + gtk_layer_set_monitor(gtk_window, monitor); + + // set window background to transparent + GtkCssProvider *css_provider = gtk_css_provider_new(); + char *css = "window {background-color: transparent;}" + "#title {color: red;}"; + gtk_css_provider_load_from_data(css_provider, css, strlen(css), NULL); + GtkStyleContext *context = gtk_widget_get_style_context(GTK_WIDGET(gtk_window)); + gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER); + + + // render label + GtkWidget *label = gtk_label_new(""); + gtk_label_set_markup(GTK_LABEL(label), text); + gtk_container_add(GTK_CONTAINER(gtk_window), label); + gtk_container_set_border_width(GTK_CONTAINER(gtk_window), 12); + gtk_widget_show_all(GTK_WIDGET(gtk_window)); +} + +static void activate(GtkApplication *app, void *data) +{ + struct config *conf = (struct config*) data; + + int title_len = strlen(conf->title); + int subtitle_len = strlen(conf->subtitle); + int len = 100+title_len+subtitle_len; + char text[len]; + + snprintf(text, len, "%s\n%s", conf->title, conf->subtitle); + + //GtkWidget *monitor_selection = monitor_selection_new(gtk_window); + GdkDisplay *display = gdk_display_get_default (); + for (int i = 0; i < gdk_display_get_n_monitors(display); i++) { + GdkMonitor *monitor = gdk_display_get_monitor(display, i); + draw_window(monitor, text, app); + } +} + +int main(int argc, char **argv) +{ + struct config conf; + conf.title = "Activate Linux"; + conf.subtitle = "Go to Settings to activate Linux."; + GtkApplication *app = gtk_application_new(NULL, G_APPLICATION_FLAGS_NONE); + g_signal_connect(app, "activate", G_CALLBACK(activate), (void *) &conf); + int status = g_application_run(G_APPLICATION(app), 0, NULL); + g_object_unref(app); + return status; +}