Skip to content

Commit 2a69571

Browse files
use gdk_threads_add_idle_full(); update readme
1 parent 6fd422d commit 2a69571

File tree

5 files changed

+59
-21
lines changed

5 files changed

+59
-21
lines changed

keyboard.c

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1+
2+
// this code mostly comes from here: https://github.com/anko/xkbcat/blob/master/xkbcat.c
3+
14
#include "keyboard.h"
25
#include "vangoghflow.h"
36

47
#include <X11/XKBlib.h>
58
#include <X11/extensions/XInput2.h>
69

7-
const char *DEFAULT_DISPLAY = ":0";
8-
const bool DEFAULT_PRINT_UP = false;
9-
1010
int xiOpcode;
11-
char xDisplayName[2];
12-
bool printKeyUps = DEFAULT_PRINT_UP;
1311
Display *disp;
1412

1513
bool initKB()
1614
{
1715

18-
// Connect to X display
16+
// Connect to X display
1917
// this is just harded for now...
2018
disp = XOpenDisplay(":0");
2119
if (NULL == disp)
2220
{
23-
fprintf(stderr, "Cannot open X display: %s\n", xDisplayName);
21+
fprintf(stderr, "Cannot open X display: %s\n", ":0");
2422
return false;
2523
}
2624

@@ -54,8 +52,6 @@ bool initKB()
5452
m.mask_len = XIMaskLen(XI_LASTEVENT);
5553
m.mask = calloc(m.mask_len, sizeof(char));
5654
XISetMask(m.mask, XI_RawKeyPress);
57-
if (printKeyUps)
58-
XISetMask(m.mask, XI_RawKeyRelease);
5955
XISelectEvents(disp, root, &m, 1 /*number of masks*/);
6056
XSync(disp, false);
6157
free(m.mask);
@@ -92,7 +88,7 @@ void *CheckForHotKeys()
9288
if (NULL == str)
9389
continue;
9490

95-
DoUpdate(str);
91+
gdk_threads_add_idle_full(G_PRIORITY_DEFAULT_IDLE, DoUpdate, str, NULL);
9692
break;
9793
}
9894
}

readme.md

+37-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
1-
#ABOUT
1+
# ABOUT
22

3-
GTK3 version of VanGoghFlow, a program for overlaying your display with beautiful visualizations pulled from YouTube.
4-
In addition to being aesthetically pleasing, it is useful for modulating brain states between focused and diffuse modes.
3+
GTK3 version of VanGoghFlow, a program for overlaying your display with beautiful visualizations pulled from YouTube. In addition to being aesthetically pleasing, it is useful for gently inducing psychological flow states.
54

65
For more information on that, please see here: https://www.kundalinisoftware.com/van-gogh-flow/
76

8-
Source code available on GitHub here: https://github.com/BenjaminPritchard/VanGoghFlowGTK3. If you have any ideas, please feel free to fork and submit a pull request.
7+
# USAGE
98

10-
#CREDITS
9+
Just run the executable. You can use your F3 / F4 keys like "volume keys" to set the opacity of the visualizations.
1110

12-
Original author: Benjamin Pritchard.
11+
To change visualizations, use the tray icon.
12+
13+
# BUILDING
14+
15+
Just run make, which builds using clang.
16+
17+
You can see the dependancies needed by looking at the makefile:
18+
19+
clang -g -O0 -std=c11 -Wdeprecated vangoghflow.c tray.c screen.c keyboard.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` -lX11 -lXi
20+
21+
# TODO
22+
23+
1. Use local .HTML instead of just setting the YouTube URL directly. This will allow the use of the YouTube API to know when the videos are done playing, so that we can automatically advance to the next one.
24+
25+
Additionally, using local .HTML opens up the possibility to do realtime visualizations using Javascript, instead of just using prerendered ones from YouTube.
26+
27+
2. Allow user-configurable YouTube video configuration. Currently this is hardcoded.
28+
29+
3. It would be nice to package this up as a .deb file.
30+
31+
# CAVEAT
32+
33+
I am not sure what all systems this builds / works under. But for sure you need a [compositing window manager](https://en.wikipedia.org/wiki/Compositing_window_manager) for this to work, and I think a GKT desktop. I use Linux Mint (which comes with a compositing window manager called Muffin) and everything works fine.
34+
35+
So maybe it is possible to get this working on different distros. But I have not tried. If you do something like that, please submit a pull request so others can benefit.
36+
37+
# GITHUB
38+
39+
Source code available on GitHub here: https://github.com/BenjaminPritchard/VanGoghFlowGTK3. If you have any ideas or improvements, please feel free to fork and submit a pull request.
40+
41+
# CREDITS
42+
43+
Original author: Benjamin Pritchard, August 2021.

tray.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ about_menu_clicked(GtkWidget *widget, gpointer data)
5151
static void
5252
item_clicked_cb(GtkWidget *widget, gpointer data)
5353
{
54-
5554
static bool noRecursion;
5655

56+
// trying to set the menu items to checked/unchecked using gtk_check_menu_item_set_active()
57+
// causes this function to be called again!!
5758
if (noRecursion)
5859
return;
5960

@@ -78,10 +79,10 @@ item_clicked_cb(GtkWidget *widget, gpointer data)
7879
break;
7980
}
8081

81-
noRecursion = false;
82-
8382
//loadURL() does range checking
8483
loadURL(web_view, index);
84+
85+
noRecursion = false;
8586
}
8687

8788
void MakeTrayIcon()

vangoghflow.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ void startKeyBDThread()
6565
GThread *myThread = g_thread_new(NULL, (GThreadFunc)CheckForHotKeys, NULL);
6666
}
6767

68-
void DoUpdate(char *key)
68+
// this routine is called by the thread created in startKeyBDThread()
69+
// by using gdk_threads_add_idle_full()
70+
// My understanding is that using gdk_threads_add_idle() is the way
71+
// we are suppossed to pass data from the background thread back to our
72+
// UI thread here
73+
gboolean DoUpdate(void *data)
6974
{
75+
char *key = (char *)data;
7076
if (strcmp(key, "F3") == 0)
7177
{
7278
if (opacity != 0.0)
@@ -79,6 +85,10 @@ void DoUpdate(char *key)
7985
}
8086

8187
gtk_widget_set_opacity(GTK_WIDGET(window), opacity);
88+
89+
// i think we have to return false each time, so that this routine won't be called more than one
90+
// per invocation of gdk_threads_add_idle()
91+
return false;
8292
}
8393

8494
int main(int argc, char **argv)

vangoghflow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#include <webkit2/webkit2.h>
44

55
void loadURL(WebKitWebView *web_view, int index);
6-
void DoUpdate(char *key);
6+
gboolean DoUpdate(void *data);

0 commit comments

Comments
 (0)