Skip to content
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

Closed
wants to merge 14 commits into from

Conversation

make-42
Copy link
Contributor

@make-42 make-42 commented Jul 11, 2024

This works...

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

Closes #59

Copy link
Owner

@nikp123 nikp123 left a 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";
Copy link
Owner

@nikp123 nikp123 Jul 12, 2024

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);
Copy link
Owner

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;
Copy link
Owner

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;
Copy link
Owner

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.

@@ -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;
Copy link
Owner

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.

@@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same story applies here

@@ -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";
Copy link
Owner

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

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

I'll do my best!

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

I'll do my best!

Good luck and have fun

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

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.

Copy link
Owner

@nikp123 nikp123 left a 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");
Copy link
Owner

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 ;)

Copy link
Owner

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;
Copy link
Owner

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.

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

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.

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.

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

something like this? it crashes here though (null pointer dereference)
src/xava.c

58    output->func.clear(xava);

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

Funnily enough it doesn't for me, can you clear the compile cache, maybe somethings up.

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

I'm on X11, that might be the issue. the clear function might be erroring out on x11.

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

There seems to be an bug with IONotify since it keeps calling non-stop.

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

Maybe yes

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

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 redrawWindow might be the solution here.

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

What do you mean by checking for an event instead of blindly reloading?

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

oh

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

i get it

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

Anyway I fixed it, sending the patch soon enough

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

Okay

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

fixes.patch.zip

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

Apply that patch, push here and I'll rebase

Additionally test out how it works for you.

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

Remove the glDrawArrays line I added by accident, it shouldn't be there

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

Actually don't, let me squash and merge this.

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

okay

@nikp123 nikp123 closed this Jul 12, 2024
@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

It doesn't crash but doesn't update the colors either on X11 until a restart.

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

It doesn't crash but doesn't update the colors either on X11 until a restart.

Hm weird

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

It doesn't crash but doesn't update the colors either on X11 until a restart.

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?

@make-42
Copy link
Contributor Author

make-42 commented Jul 12, 2024

config

@nikp123
Copy link
Owner

nikp123 commented Jul 12, 2024

config

works even with that config 🤔

@make-42
Copy link
Contributor Author

make-42 commented Jul 13, 2024

I'll do some investigation

@make-42
Copy link
Contributor Author

make-42 commented Jul 13, 2024

Okay. I fixed it. Line 18 of pywal.c it's ".cache" and not ".config" that should be used.

@make-42
Copy link
Contributor Author

make-42 commented Jul 13, 2024

It didn't register the file properly and probably read from xrdb on startup instead.

@make-42
Copy link
Contributor Author

make-42 commented Jul 13, 2024

fix.zip

@nikp123
Copy link
Owner

nikp123 commented Jul 13, 2024

@make-42 oh whoops, my bad

sent the patch to master

@make-42
Copy link
Contributor Author

make-42 commented Jul 13, 2024

Haha! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants