siduck / chadwm

Making dwm as beautiful as possible!
MIT License
2.16k stars 170 forks source link

[Feature] Add tag preview (WIP) #6

Closed siduck closed 3 years ago

siduck commented 3 years ago

show a floating picture like thingy for tags when their icons on dwmbar is hovered, something like this

https://cdn.discordapp.com/attachments/635625917623828520/829478089469329438/gif_2021-04-07032620.gif (awesomewm)

siduck commented 3 years ago

so far I was able to preview an image with rofi and align it properly.

https://user-images.githubusercontent.com/59060246/127742682-861304c5-c081-426b-ae3e-4674ee5a0cf9.mp4

siduck commented 3 years ago
#!/bin/sh

preview_dir="$HOME/.dwm/tag_previews/"

current_tag=$(wmctrl -d | grep '*' | cut -d ' ' -f1)

save_Screenshot() {
  file="${preview_dir}${current_tag}.png"
  maim -u "${file}"
}

$(save_Screenshot)
siduck commented 3 years ago

The above script should be excuted by dwm before the user switches to another workspace. (this is for saving the screenshots )

maim will overwrite the screenshots itself too.

siduck commented 3 years ago

Basic Concept

  1. Run the above save_screenshot script before switching tags
    • suppose there are 5 workspaces ( 0 to 4 according to wmctrl )

image

  1. When you hover on the tag icon , it should execute 2 things :

sed -i "s:/home/sid/.*.png:/home/sid/$screenshot:" ~/.config/rofi/tag.rasi


And 

-  run [tag_preview script](https://paste.sh/HX3tOdA_#Pv67BPdzQ_IgoVzsMM5w_rH-)

I shouldnt worry about the alignment , I'll manage it in the tag_preview script.
siduck commented 3 years ago

https://user-images.githubusercontent.com/59060246/127776548-f5c22a36-8801-46a2-bbea-b687e8a86eef.mp4

works kinda ( but switching tags adds 100ms ~ delay ) :(

siduck commented 3 years ago

https://user-images.githubusercontent.com/59060246/127789831-81e0a856-8032-4241-b180-29c3a5aacba5.mp4

after using jpeg for image format , it feels faster than before!

siduck commented 3 years ago

using feh instead of rofi is much faster!

https://user-images.githubusercontent.com/59060246/127867063-ba7572fd-bdb6-413e-98c1-ce348395f5b0.mp4

siduck commented 3 years ago
  1. So we dont need some hooks stuff , since the tag preview is accurate (but not for current tag). the rest of the tags already have accurate previews ,since we're taking screenshot before switching the tag.

look

https://user-images.githubusercontent.com/59060246/127945072-45f1bd3b-9b34-4d86-8a49-4bb4d9fb29e7.mp4

siduck commented 3 years ago

Issue 2 :

If there's an inactive tag , do not show its tag preview.

behaviour :

https://user-images.githubusercontent.com/59060246/127945471-32eb62d6-6935-4cde-8620-ebea330f759c.mp4

Solution :

just delete its image from the ~/.dwm/tag_previews dir soo in our case 3 was the inactive tag , so remove 3.jpeg :)

if we hover an empty tag

siduck commented 3 years ago

finally my friend made a patch for this! so no external scripts xD

https://github.com/siduck76/chadwm/commit/0372264f1de4aa3487a0c1643051dd5746e0e581

siduck commented 3 years ago

stuff needs to be fixed : tag preview doesnt update the current workspace screenshot

https://user-images.githubusercontent.com/59060246/128020404-0938f06f-75d9-490f-8cc0-bb28b873691e.mp4

solution : whenever we hover current tag icon , take screenshot + do tag preview

siduck commented 3 years ago

https://user-images.githubusercontent.com/59060246/128049070-338f3cec-ac21-4a4a-ae42-ca23ef035839.mp4

siduck commented 3 years ago

https://github.com/siduck76/chadwm/commit/75168cc5d5efe9d34b00318259244ff60ccafd20

siduck commented 3 years ago

dwm ram usage keeps increasing if I switch to a different tag

https://user-images.githubusercontent.com/59060246/128053620-632f043b-b037-4a3b-a5c1-f2cb9241d620.mp4

siduck commented 3 years ago

dwm ram usage keeps increasing if I switch to a different tag

simplescreenrecorder-2021-08-03_21.49.19.mp4

temp fix https://pastebin.com/raw/rThCDTZ6

siduck commented 3 years ago

dwm ram usage keeps increasing if I switch to a different tag

simplescreenrecorder-2021-08-03_21.49.19.mp4

fixed here https://github.com/siduck76/chadwm/commit/a10d00f9e0329e787b490e54182f15394e41b583

siduck commented 3 years ago

dwm will know take around 11mb to 32~ mb , since its storing the images in ram rather than disk . I'll test it the other way around ( saving images on disk).

siduck commented 3 years ago

FINALLY DONE https://github.com/siduck76/chadwm/commit/f397a51a8e9b093994bc663be4d98cc7150bdb81

thanks a lot to /u/eProTaLT83 for helping with this feature!!

explosion-mental commented 3 years ago

Hi, made a patch for this, which of course I can maintain.

Let me suggest to put it on the patches section since I know some are too comfy on their builds to switch.

siduck commented 3 years ago

Hi, made a patch for this, which of course I can maintain.

Let me suggest to put it on the patches section since I know some are too comfy on their builds to switch.

Thanks for this! if you don't mind then you could add the tabbed with colored buttons patch too.

explosion-mental commented 3 years ago

Thanks for this! if you don't mind then you could add the tabbed with colored buttons patch too.

You mean this ?

siduck commented 3 years ago

Thanks for this! if you don't mind then you could add the tabbed with colored buttons patch too.

You mean this ?

yes

explosion-mental commented 3 years ago

Sorry for the late response but the patch finally got pushed. Also by

Let me suggest to put it on the patches section since I know some are too comfy on their builds to switch.

I meant to the readme of your repo lol. Anyway it's now pushed on the link above.

As for

if you don't mind then you could add the tabbed with colored buttons patch too.

I could but I wouln't be able to keep it up to date.

Maybe the author of the patch is interested on it? see

siduck commented 3 years ago

@explosion-mental The author of the patch is /u/eProTaLT83 on reddit . I came up with this idea and he made a patch for it!

renanwp2 commented 2 years ago

At least in my build of DWM, with the patch of explosion-mental, I have some problem with scaling variable. If I set it to 2 (static const int scalepreview= 2), the window size does not increase, but it still zooms the image. It would be better if the window size increases together. Probably an error in the calculation of XCopyArea.

baizeyv commented 2 years ago

At least in my build of DWM, with the patch of explosion-mental, I have some problem with scaling variable. If I set it to 2 (static const int scalepreview= 4), the window size does not increase, but it still zooms the image. It would be better if the window size still increases. Probably an error in the calculation of XCopyArea.

you can modify this function

+void
+updatepreview(void)
+{
+   Monitor *m;
+
+   XSetWindowAttributes wa = {
+       .override_redirect = True,
+       .background_pixmap = ParentRelative,
+       .event_mask = ButtonPressMask|ExposureMask
+   };
+   for (m = mons; m; m = m->next) {
+       m->tagwin = XCreateWindow(dpy, root, m->wx, m->by + bh, m->mw / 4, m->mh / 4, 0,
+               DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
+               CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+       XDefineCursor(dpy, m->tagwin, cursor[CurNormal]->cursor);
+       XMapRaised(dpy, m->tagwin);
+       XUnmapWindow(dpy, m->tagwin);
+   }
+}
+

modify this to

+void
+updatepreview(void)
+{
+   Monitor *m;
+
+   XSetWindowAttributes wa = {
+       .override_redirect = True,
+       .background_pixmap = ParentRelative,
+       .event_mask = ButtonPressMask|ExposureMask
+   };
+   for (m = mons; m; m = m->next) {
+       m->tagwin = XCreateWindow(dpy, root, m->wx, m->by + bh, m->mw / scalepreview, m->mh / scalepreview, 0,
+               DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
+               CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+       XDefineCursor(dpy, m->tagwin, cursor[CurNormal]->cursor);
+       XMapRaised(dpy, m->tagwin);
+       XUnmapWindow(dpy, m->tagwin);
+   }
+}
+

This solution maybe will handle your problem.

renanwp2 commented 2 years ago

At least in my build of DWM, with the patch of explosion-mental, I have some problem with scaling variable. If I set it to 2 (static const int scalepreview= 4), the window size does not increase, but it still zooms the image. It would be better if the window size still increases. Probably an error in the calculation of XCopyArea.

you can modify this function

+void
+updatepreview(void)
+{
+ Monitor *m;
+
+ XSetWindowAttributes wa = {
+     .override_redirect = True,
+     .background_pixmap = ParentRelative,
+     .event_mask = ButtonPressMask|ExposureMask
+ };
+ for (m = mons; m; m = m->next) {
+     m->tagwin = XCreateWindow(dpy, root, m->wx, m->by + bh, m->mw / 4, m->mh / 4, 0,
+             DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
+             CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+     XDefineCursor(dpy, m->tagwin, cursor[CurNormal]->cursor);
+     XMapRaised(dpy, m->tagwin);
+     XUnmapWindow(dpy, m->tagwin);
+ }
+}
+

modify this to

+void
+updatepreview(void)
+{
+ Monitor *m;
+
+ XSetWindowAttributes wa = {
+     .override_redirect = True,
+     .background_pixmap = ParentRelative,
+     .event_mask = ButtonPressMask|ExposureMask
+ };
+ for (m = mons; m; m = m->next) {
+     m->tagwin = XCreateWindow(dpy, root, m->wx, m->by + bh, m->mw / scalepreview, m->mh / scalepreview, 0,
+             DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
+             CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+     XDefineCursor(dpy, m->tagwin, cursor[CurNormal]->cursor);
+     XMapRaised(dpy, m->tagwin);
+     XUnmapWindow(dpy, m->tagwin);
+ }
+}
+

This solution maybe will handle your problem.

I don't believe that it was only it! Just exchange a four by the variable. I think this bug fix should be on dwm suckless site as well.

baizeyv commented 2 years ago

@renanwp2 This patch is not mine, I just found this little bug during debugging. The creator of this patch is explosion-mental.