Skip to content

Commit 27a002d

Browse files
first commit
0 parents  commit 27a002d

13 files changed

+674
-0
lines changed

.vscode/c_cpp_properties.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"env": {
3+
"myDefaultIncludePath": [
4+
"${workspaceFolder}",
5+
"${workspaceFolder}/include"
6+
],
7+
"myCompilerPath": "usr/bin/clang"
8+
},
9+
"configurations": [
10+
{
11+
"name": "include paths",
12+
"intelliSenseMode": "linux-clang-x64",
13+
"includePath": [
14+
"/usr/include/gtk-3.0",
15+
"/usr/include/at-spi2-atk/2.0",
16+
"/usr/include/at-spi-2.0",
17+
"/usr/include/dbus-1.0",
18+
"/usr/lib/x86_64-linux-gnu/dbus-1.0/include",
19+
"/usr/include/gtk-3.0",
20+
"/usr/include/gio-unix-2.0",
21+
"/usr/include/cairo",
22+
"/usr/include/pango-1.0",
23+
"/usr/include/harfbuzz",
24+
"/usr/include/pango-1.0",
25+
"/usr/include/fribidi",
26+
"/usr/include/atk-1.0",
27+
"/usr/include/cairo",
28+
"/usr/include/pixman-1",
29+
"/usr/include/freetype2",
30+
"/usr/include/libpng16",
31+
"/usr/include/gdk-pixbuf-2.0",
32+
"/usr/include/libmount",
33+
"/usr/include/blkid",
34+
"/usr/include/uuid",
35+
"/usr/include/glib-2.0",
36+
"/usr/lib/x86_64-linux-gnu/glib-2.0/include",
37+
"/usr/include/webkitgtk-4.0",
38+
"/usr/include/libsoup-2.4/",
39+
"/usr/include/libappindicator-0.1/libappindicator/",
40+
"/usr/include/libdbusmenu-glib-0.4/libdbusmenu-glib/"
41+
],
42+
"compilerPath": "/usr/bin/clang",
43+
"cStandard": "c11",
44+
"cppStandard": "c++17",
45+
"browse": {
46+
"path": [
47+
"${workspaceFolder}"
48+
],
49+
"limitSymbolsToIncludedHeaders": true,
50+
"databaseFilename": ""
51+
}
52+
}
53+
],
54+
"version": 4
55+
}

.vscode/launch.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"name": "debug with gdb (no build)",
10+
"type": "cppdbg",
11+
"request": "launch",
12+
"program": "${workspaceRoot}/hudkit",
13+
"args": [],
14+
"stopAtEntry": false,
15+
"cwd": "${workspaceRoot}",
16+
"environment": [],
17+
"externalConsole": false,
18+
"MIMode": "gdb",
19+
"setupCommands": [
20+
{
21+
"description": "Enable pretty-printing for gdb",
22+
"text": "-enable-pretty-printing",
23+
"ignoreFailures": true
24+
}
25+
],
26+
"preLaunchTask": "",
27+
"miDebuggerPath": "/usr/bin/gdb"
28+
}
29+
]
30+
}

.vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"files.associations": {
3+
"gdk.h": "c",
4+
"gtk.h": "c",
5+
"webkit2.h": "c",
6+
"webkitcookiemanager.h": "c",
7+
"vangoghflow.h": "c",
8+
"app-indicator.h": "c"
9+
}
10+
}

.vscode/tasks.json

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"type": "shell",
3+
"label": "gcc debug build active file - with GTK",
4+
"command": "/usr/bin/clang",
5+
"args": [
6+
"-g",
7+
8+
"-pthread",
9+
"-I/usr/include/gtk-3.0",
10+
"-I/usr/include/at-spi2-atk/2.0",
11+
"-I/usr/include/at-spi-2.0",
12+
"-I/usr/include/dbus-1.0",
13+
"-I/usr/lib/x86_64-linux-gnu/dbus-1.0/include",
14+
"-I/usr/include/gtk-3.0",
15+
"-I/usr/include/gio-unix-2.0",
16+
"-I/usr/include/cairo",
17+
"-I/usr/include/libdrm",
18+
"-I/usr/include/pango-1.0",
19+
"-I/usr/include/harfbuzz",
20+
"-I/usr/include/pango-1.0",
21+
"-I/usr/include/fribidi",
22+
"-I/usr/include/atk-1.0",
23+
"-I/usr/include/cairo",
24+
"-I/usr/include/pixman-1",
25+
"-I/usr/include/freetype2",
26+
"-I/usr/include/libpng16",
27+
"-I/usr/include/gdk-pixbuf-2.0",
28+
"-I/usr/include/libmount",
29+
"-I/usr/include/blkid",
30+
"-I/usr/include/uuid",
31+
"-I/usr/include/glib-2.0",
32+
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
33+
34+
"${file}",
35+
36+
"-lgtk-3",
37+
"-lgdk-3",
38+
"-lpangocairo-1.0",
39+
"-lpango-1.0",
40+
"-latk-1.0",
41+
"-lcairo-gobject",
42+
"-lcairo",
43+
"-lgdk_pixbuf-2.0",
44+
"-lgio-2.0",
45+
"-lgobject-2.0",
46+
"-lglib-2.0",
47+
48+
"-o",
49+
"${fileDirname}/${fileBasenameNoExtension}"
50+
],
51+
"options": {
52+
"cwd": "/usr/bin"
53+
},
54+
"problemMatcher": [
55+
"$gcc"
56+
],
57+
"group": {
58+
"kind": "build",
59+
"isDefault": true
60+
}
61+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Benjamin Pritchard
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

kill.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/sh
2+
kill `ps -A | grep vangoghflow | awk '{print $1}'`

makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vangoghflow: vangoghflow.c
2+
clang -g -O0 -std=c11 -Wdeprecated vangoghflow.c tray.c screen.c -o vangoghflow -lappindicator3 -I/usr/include/libdbusmenu-glib-0.4/libdbusmenu-glib/ -I/usr/include/libappindicator-0.1/libappindicator `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0`
3+
4+
clean:
5+
rm -f vangoghflow

screen.c

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
2+
// all the code in here is taken (and maybe slightly adapted) from: XXX
3+
4+
#include "screen.h"
5+
6+
gulong monitors_changed_handler_id = 0;
7+
8+
// This callback runs when the window is first set to appear on some screen, or
9+
// when it's moved to appear on another.
10+
void screen_changed(GtkWidget *widget, GdkScreen *old_screen,
11+
gpointer user_data)
12+
{
13+
GdkScreen *screen = gtk_widget_get_screen(widget);
14+
15+
WebKitWebView *web_view = (WebKitWebView *)user_data;
16+
17+
// Die unless the screen supports compositing (alpha blending)
18+
if (!gdk_screen_is_composited(screen))
19+
{
20+
fprintf(stderr, "Your screen does not support transparency.\n");
21+
fprintf(stderr, "Maybe your compositor isn't running?\n");
22+
exit(69); // memes
23+
}
24+
25+
// Ensure the widget can take RGBA
26+
gtk_widget_set_visual(widget, gdk_screen_get_rgba_visual(screen));
27+
28+
// Switch monitors-changed subscription from the old screen (if applicable)
29+
// to the new one
30+
if (old_screen)
31+
g_signal_handler_disconnect(old_screen, monitors_changed_handler_id);
32+
33+
size_to_screen(GTK_WINDOW(widget));
34+
}
35+
36+
int get_monitor_rects(GdkDisplay *display, GdkRectangle **rectangles)
37+
{
38+
int n = gdk_display_get_n_monitors(display);
39+
GdkRectangle *new_rectangles = (GdkRectangle *)malloc(n * sizeof(GdkRectangle));
40+
for (int i = 0; i < n; ++i)
41+
{
42+
GdkMonitor *monitor = gdk_display_get_monitor(display, i);
43+
gdk_monitor_get_geometry(monitor, &new_rectangles[i]);
44+
}
45+
*rectangles = new_rectangles;
46+
// Ownership of the malloc'd memory transfers out
47+
return n;
48+
}
49+
50+
// tell GTK that the entire window should be a clickthough region
51+
void make_entire_window_clickthrough()
52+
{
53+
cairo_rectangle_int_t rect = {0, 0, 0, 0};
54+
55+
cairo_region_t *shape =
56+
cairo_region_create_rectangle(&rect);
57+
58+
GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(window));
59+
60+
if (gdk_window)
61+
gdk_window_input_shape_combine_region(gdk_window, shape, 0, 0);
62+
63+
cairo_region_destroy(shape);
64+
}
65+
66+
void size_to_screen(GtkWindow *window)
67+
{
68+
GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(window));
69+
70+
// Get total screen size. This involves finding all physical monitors
71+
// connected, and examining their positions and sizes. This is as complex
72+
// as it is because monitors can be configured to have relative
73+
// positioning, causing overlapping areas and a non-rectangular total
74+
// desktop area.
75+
//
76+
// We want our window to cover the minimum axis-aligned bounding box of
77+
// that total desktop area. This means it's too large (even large bits of
78+
// it may be outside the accessible desktop) but it's easier to manage than
79+
// multiple windows.
80+
81+
GdkDisplay *display = gdk_display_get_default();
82+
GdkRectangle *rectangles = NULL;
83+
int nRectangles = get_monitor_rects(display, &rectangles);
84+
85+
// I can't think of a reason why someone's monitor setup might have a
86+
// monitor positioned origin at negative x, y coordinates, but just in case
87+
// someone does, we'll cover for it.
88+
int x = 0, y = 0, width = 0, height = 0;
89+
for (int i = 0; i < nRectangles; ++i)
90+
{
91+
GdkRectangle rect = rectangles[i];
92+
int left = rect.x;
93+
int top = rect.y;
94+
int right = rect.x + rect.width;
95+
int bottom = rect.y + rect.height;
96+
if (left < x)
97+
x = left;
98+
if (top < y)
99+
y = top;
100+
if (width < right)
101+
width = right;
102+
if (height < bottom)
103+
height = bottom;
104+
}
105+
free(rectangles);
106+
107+
gtk_window_move(GTK_WINDOW(window), x, y);
108+
gtk_window_set_default_size(window, width, height);
109+
gtk_window_resize(window, width, height);
110+
gtk_window_set_resizable(window, false);
111+
}

screen.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include <gtk/gtk.h>
4+
#include <gdk/gdk.h>
5+
#include <gdk/gdkmonitor.h>
6+
#include <webkit2/webkit2.h>
7+
8+
#define MIN_FONT_SIZE 4
9+
10+
GtkWidget *window;
11+
WebKitWebView *web_view;
12+
13+
void loadURL(WebKitWebView *web_view, char *target_url);
14+
15+
void screen_changed(GtkWidget *widget, GdkScreen *old_screen,
16+
gpointer user_data);
17+
int get_monitor_rects(GdkDisplay *display, GdkRectangle **rectangles);
18+
void size_to_screen(GtkWindow *window);
19+
void make_entire_window_clickthrough();

0 commit comments

Comments
 (0)