-
Notifications
You must be signed in to change notification settings - Fork 17
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
Render drop shadow for active window #58
base: main
Are you sure you want to change the base?
Conversation
61764af
to
94f960d
Compare
Because I'm still unsure where to place the blur operation, whether to implement the blur in '_twin_widget_queue_paint()', as this function handles the rendering order of each widget object. It would need to read the corresponding pixel block currently on the screen during rendering to blur the current background. Or should I implement this operation when each widget's TwinEventPaint occurs? So I first try to implement this function on the background to see its effect. |
Alternatively, you can write an image viewer with drop shadow functionality to evaluate performance and visual effects in the initial stage. Once you have a better understanding of the window manager events and their flow, we can proceed with integrating it into the window system. See MDN: drop-shadow |
For performance evaluation, you may consider the code mentioned in #55 (comment) . |
94f960d
to
5dda144
Compare
I haven't applied stack blur to the drop shadow yet, because I don't know how to access the current screen's topmost pixel map. I want to apply the stack blur to a specific region of the topmost pixel map that overlaps with the shadow and then use this as the new shadow. The topmost pixel map is efficiently updated by refreshing only the damaged areas. |
a78fc51
to
3433384
Compare
Compilation error/warning reported by Clang:
|
3433384
to
dcbefd0
Compare
I am unsure how to validate this. Could you provide the relevant procedures or methods along with the expected behavior? |
dcbefd0
to
397f8e9
Compare
The blur appeared too strong and spread out compared to typical drop shadow effects found in compositing window managers. Would you adjust the Gaussian kernel to create a tighter, more natural-looking shadow? |
Do you want to directly reduce kernel size or use the gradient method to reduce kernel size? |
For window compositing, the blur effect should only be applied to the window decorator when creating drop shadows, not to the entire window. The kernel size shrinks. |
397f8e9
to
e403354
Compare
Do all windows need to have the drop shadow feature? And only the window on the top layer will display the drop shadow. |
Blur effects are only applied to the active window, using drop shadow to make it visually distinct. |
e403354
to
80bd59e
Compare
The latest update enforces blur effects on the active window, matching the standard behavior of compositing window managers. To enhance the visual depth, we should replace the right and bottom window borders with drop shadows, creating darker edges that give a more dimensional appearance. This means disabling the standard border rendering on those sides and implementing drop shadow effects instead. Reference video: Apply Blur to xfce 4 Desktop Manager |
Yes, exactly. |
80bd59e
to
a78fe42
Compare
f02804b
to
58766b2
Compare
This version will use the |
e866c9d
to
6296804
Compare
This version adds an implementation in the function |
6296804
to
29368a6
Compare
@@ -286,4 +331,5 @@ void apps_multi_start(twin_screen_t *screen, | |||
apps_ascii_start(screen, x += 20, y += 20, w, h); | |||
apps_jelly_start(screen, x += 20, y += 20, w / 2, h); | |||
apps_flower_start(screen, x += 20, y += 20, w, h); | |||
apps_blur(screen, x += 20, y += 20, w / 2, h / 2); |
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 don't think it is worthy to have an application for stack blur. Any idea to keep it?
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.
The apps_blur() function currently only resizes tux.png. This function isn't worthwhile to show by creating a standalone window feature. If it is still not worthy to have an application by adding another function, "blur," the apps_blur() function could be removed entirely.
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.
The drop shadow feature's availability depends on configuration settings, so it should not expose any public functions.
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.
The drop shadow functionality relies on the blur effect, but the blur effect is designed to be used independently as well. This is why in draw.c, the function twin_shadow_border() is conditionally built, while the function twin_stack_blur() is not.
When using xcompmgr with the arguments |
29368a6
to
4eb5284
Compare
Is it feasible to eliminate the extra gap by skipping resize icon? That is, --- a/src/window.c
+++ b/src/window.c
@@ -274,12 +274,6 @@ static void twin_window_frame(twin_window_t *window)
twin_matrix_translate(&m, close_x, icon_y);
twin_matrix_scale(&m, icon_size, icon_size);
twin_icon_draw(pixmap, TwinIconClose, m);
-
- twin_matrix_identity(&m);
- twin_matrix_translate(&m, resize_x, resize_y);
- twin_matrix_scale(&m, twin_int_to_fixed(TWIN_TITLE_HEIGHT),
- twin_int_to_fixed(TWIN_TITLE_HEIGHT));
- twin_icon_draw(pixmap, TwinIconResize, m);
}
twin_pixmap_clip(pixmap, window->client.left, window->client.top, |
4eb5284
to
4fb685a
Compare
4fb685a
to
4a2aff8
Compare
This modification removes the original extra gap while retaining the original resized icon. |
8255976
to
c598a47
Compare
Add the twin_stack_blur() function to implement Mario's Stack Blur algorithm, which blurs the target pixel map. Additionally, create a blur window to show the effect of twin_stack_blur(). Implement the twin_drop_shadow() function to handle the pixels within the drop shadow area of the active window's pixel map. The drop shadow effect of the window is only visible when the window is on the top layer, ensuring the active window stands out visually. Implement the twin_shadow_border() function to create a darker border of the active window that gives a more dimensional appearance. In the twin_drop_shadow() function, twin_stack_blur() will apply a blur effect to the pixels beneath the active window's pixel map, which aims to create a frosted glass appearance. Furthermore, implement the twin_cover() function to cover the target pixels with the desired color. Ref: https://melatonin.dev/blog/implementing-marios-stack-blur-15-times-in-cpp/ Close sysprog21#34 Signed-off-by: Wei-Hsin Yeh <[email protected]>
c598a47
to
3c8aa5a
Compare
It looks much better now! However, when Pixman based rendering is used, there is no drop shadow appearing. |
@@ -272,6 +273,50 @@ static void apps_flower_start(twin_screen_t *screen, int x, int y, int w, int h) | |||
twin_window_show(window); | |||
} | |||
|
|||
static void apps_blur(twin_screen_t *screen, int x, int y, int w, int h) |
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 function should be built only if PNG support is specified.
* Add a shadowed area to the pixel map of the window to create a drop | ||
* shadow effect. | ||
*/ | ||
window->shadow_x = 10, window->shadow_y = 10; |
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.
Maybe you could define 10 as a macro with a meaningful name here.
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.
Furthermore, use Kconfig to specify the shadow related configurations.
@@ -205,6 +338,11 @@ void twin_screen_update(twin_screen_t *screen) | |||
|
|||
prev_active_pix = twin_active_pixmap(screen, &active_pix); | |||
|
|||
#if defined(CONFIG_DROP_SHADOW) | |||
/* Handle drop shadow. */ | |||
twin_drop_shadow(screen, active_pix, prev_active_pix); |
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'm not sure if placing twin_drop_shadow
in twin_screen_update
is appropriate(So is the logic that handle the color of activate window). From my understanding, twin_screen_update
serves as a bridge to rendering backends, and it gets triggered whenever there are any frame updates. For example, every time a GIF frame updates, twin_screen_update
is called. With this change, every GIF frame update would require checking twin_drop_shadow
, which is redundant.
Maybe we could handle these window events in twin_window_dispatch
. I think an additional event might be needed for deactivating a window.
#define _twin_add_ARGB(s, d, i, t) (((t) = (s) + twin_get_8(d, i))) | ||
#define _twin_add(s, d, t) (((t) = (s) + (d))) | ||
#define _twin_div(d, den, i, t) \ | ||
(((t) = (d) / (den)), (t) = twin_get_8((t), 0), \ | ||
(twin_argb32_t) twin_sat(t) << (i)) | ||
#define _twin_sub_ARGB(s, d, i, t) (((t) = (s) - twin_get_8(d, i))) | ||
#define _twin_sub(s, d, t) (((t) = (s) - (d))) | ||
#define twin_put_8(d, i, t) (((t) = (d) << (i))) |
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.
Will these macros be promoted in private headers?
Use Pascal's Triangle to approximate a 5x5 Gaussian Kernel, and apply Gaussian blur on the
twin_pixmap_t
to implement the blurring technique.See: #34