-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Pull colors from pywal #60
Conversation
Closes #59 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a bunch of changes I'd like you to make, if you're not sure how to proceed, ask me for help or let me implement them myself on my own time.
src/xava.c
Outdated
@@ -224,6 +224,22 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co | |||
thing.xava = &xava; | |||
xavaIONotifyAddWatch(&thing); | |||
|
|||
// attach pywal colors file to the IONotify thing | |||
static const char b[] = "/.cache/wal/colors"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple things need to be fixed:
- I'd like to comply with the XDG base specification, this means that we should NEVER point to a specific folder, but rather let that depend on the environment variables and if they don't exist only THEN grab the hardcoded value. Since this isn't completely the first time this is done, I'd like this to be done within the src/shared (potentially a new config function??) family of functions (I'll do these myself if you don't want to make them)
- pywal support should be optional, the current implementation will fail if the user doesn't happen to use pywal. Consider users of Windows or MacOS, this will straight up fail for them
src/xava.c
Outdated
int lenb = strlen(b); | ||
char *filename = malloc(lena+lenb+1); | ||
// copy & concat (including string termination) | ||
memcpy(filename,getenv("HOME"),lena); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I may come out as not-C-like but I'd like to avoid doing pointer math as much as possible.
src/xava.c
Outdated
memcpy(filename,getenv("HOME"),lena); | ||
memcpy(filename+lena,b,lenb+1); | ||
struct xava_ionotify_watch_setup pywal; | ||
pywal.xava_ionotify_func = &handle_ionotify_call; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential improvment: Since these changes are mostly colour related, we don't really need to reload the entire visualizer, instead we can just apply colours during runtime using a seperate handle_ionotify_call
or make handle_ionotify_call
handle logic differently based on the ID parameter (we can use it to find out what triggered the callback).
Something like: XAVA_IONOTIFY_CALLBACK_MAIN
and XAVA_IONOTIFY_CALLBACK_PYWAL
just to make it clear for other people reading the code.
src/xava.c
Outdated
pywal.xava_ionotify_func = &handle_ionotify_call; | ||
pywal.filename = filename; | ||
pywal.ionotify = xava.ionotify; | ||
pywal.id = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the IONotify callback ID I'm talking about.
src/output/graphical_x11/main.c
Outdated
@@ -172,6 +172,38 @@ void calculateColors(XAVA_CONFIG *conf) { | |||
} | |||
snatchColor("color5", conf->color, &conf->col, databaseName, &xavaXResDB); | |||
snatchColor("color4", conf->bcolor, &conf->bgcol, databaseName, &xavaXResDB); | |||
int lineNumberFg = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets avoid having color logic inside of the output methods themselves, but rather move that somewhere where it could be reused easily, like one of the shared functions. This way we avoid bloating the modules themselves unnecessarily.
src/shared/config/pywal
sounds like a good place to start.
src/output/graphical_wayland/main.c
Outdated
@@ -233,6 +233,39 @@ EXP_FUNC void xavaOutputLoadConfig(XAVA *hand) { | |||
XAVA_CONFIG *p = &hand->conf; | |||
xava_config_source config = hand->default_config.config; | |||
|
|||
int lineNumberFg = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same story applies here
src/output/graphical_x11/main.c
Outdated
@@ -172,6 +172,38 @@ void calculateColors(XAVA_CONFIG *conf) { | |||
} | |||
snatchColor("color5", conf->color, &conf->col, databaseName, &xavaXResDB); | |||
snatchColor("color4", conf->bcolor, &conf->bgcol, databaseName, &xavaXResDB); | |||
int lineNumberFg = 1; | |||
int lineNumberBg = 2; | |||
static const char b[] = "/.cache/wal/colors"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same story when it comes to paths and pointer math
I'll do my best! |
Good luck and have fun |
I made all the changes you asked for except for the dynamic color reload part because I have no idea how to change the colors without triggering a whole reload. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there.
src/xava.c
Outdated
UNUSED(xavaionot); | ||
switch(id) { | ||
case XAVA_IONOTIFY_CALLBACK_MAIN: | ||
printf("triggered non pywal!\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should remove the debug printf's once you're done debugging ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also for future reference use xavaLog or xavaSpam for these kinds of purposes, it's arguments are the same as printf's.
src/xava.c
Outdated
xavaLog("ionotify socket closed"); | ||
case XAVA_IONOTIFY_CALLBACK_PYWAL: | ||
printf("triggered pywal!\n"); | ||
XAVA_CONFIG *p = &xava.conf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be the correct approach, we should trigger a window redraw instead. You're pulling the global xava reference instead of the argument which is undefined behavior.
To redraw the window move the redrawWindow if block from the main loop into its own function, call it xava_window_redraw
(just to have a consistent naming scheme) and call it with the xava argument from the callback.
Yeah because it isn't really obvious, I'd never thought of having code that redraws colors outside of the main loop, hence why a bit of architectural elbow grease is required unfortunately. |
something like this? it crashes here though (null pointer dereference)
|
Funnily enough it doesn't for me, can you clear the compile cache, maybe somethings up. |
I'm on X11, that might be the issue. the clear function might be erroring out on x11. |
There seems to be an bug with IONotify since it keeps calling non-stop. |
Maybe yes |
Ok I found out whats the bug. Firstly you should actually check for an event instead of blindly reloading. Secondly the clear call seg faults on some systems because its supposed to be called from within the main thread (OpenGL moment). We need an way to signal to the thread that we are redrawing. Exposing |
What do you mean by checking for an event instead of blindly reloading? |
oh |
i get it |
Anyway I fixed it, sending the patch soon enough |
Okay |
Apply that patch, push here and I'll rebase Additionally test out how it works for you. |
Remove the glDrawArrays line I added by accident, it shouldn't be there |
Actually don't, let me squash and merge this. |
okay |
It doesn't crash but doesn't update the colors either on X11 until a restart. |
Hm weird |
I've tested both X11 and Wayland, neither seem to have the issue on both Cairo and OpenGL Can you send your config just in case? |
works even with that config 🤔 |
I'll do some investigation |
Okay. I fixed it. Line 18 of pywal.c it's ".cache" and not ".config" that should be used. |
It didn't register the file properly and probably read from xrdb on startup instead. |
@make-42 oh whoops, my bad sent the patch to master |
Haha! Thank you! |
This works...