forked from kljunas2/activate-linux
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
bin
|
||||||
26
LICENSE.md
Normal file
26
LICENSE.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
=====================
|
||||||
|
|
||||||
|
Copyright © `<2022>` `<Miha Korenjak>`
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
11
Makefile
Normal file
11
Makefile
Normal file
@@ -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/
|
||||||
14
README.md
Normal file
14
README.md
Normal file
@@ -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
|
||||||
|
```
|
||||||
73
src/activate_linux.c
Normal file
73
src/activate_linux.c
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#include <gtk-layer-shell/gtk-layer-shell.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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, "<span font_desc=\"24.0\">%s</span>\n<span font_desc=\"16\">%s</span>", 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user