From a08c22945a825eb43607edc7317611c6b6049232 Mon Sep 17 00:00:00 2001 From: Richard Grenville Date: Wed, 19 Sep 2012 20:49:16 +0800 Subject: Improvement: Change fading mechanism - Change fading mechanism for better modularity. Remove fade queue and use members in struct _win to record fading data. In contrast to previous commits, this one actually could make the program slower (but very slightly, hardly noticeable if your CPU is anywhere close to AMD K7). As this commit changes lots of things, bugs are to be expected. - Currently -F does not do its job. -f actually equals -fF. (While in the past -F equals nothing and -f is just -f.) A fix will be made soon. I suppose it isn't hard. - Add a preprocessor function paint_preprocess() and move all preprocessing code in paint_all() to it. - Add window flag support but currently unused. - Add DamageNotify handling to ev_window(). - I'm considering removing HAS_NAME_WINDOW_PIXMAP = 0 support as I couldn't see what it is good for. Nor do I know what CAN_DO_USABLE does. Basically all my changes ignore these cases. --- compton.h | 97 ++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 38 deletions(-) (limited to 'compton.h') diff --git a/compton.h b/compton.h index 19f5f2aac..4246dc4c9 100644 --- a/compton.h +++ b/compton.h @@ -107,13 +107,12 @@ typedef struct _win { Bool destroyed; /// Cached width/height of the window including border. int widthb, heightb; - unsigned int left_width; - unsigned int right_width; - unsigned int top_width; - unsigned int bottom_width; + // Opacity-related members /// Current window opacity. opacity_t opacity; + /// Target window opacity. + opacity_t opacity_tgt; /// Opacity of current alpha_pict. opacity_t opacity_cur; /// Cached value of opacity window attribute. @@ -121,13 +120,26 @@ typedef struct _win { /// Alpha mask Picture to render window with opacity. Picture alpha_pict; + // Fading-related members + /// Do not fade if it's false. Change on window type change. + /// Used by fading blacklist in the future. + Bool fade; + /// Callback to be called after fading completed. + void (*fade_callback) (Display *dpy, struct _win *w); + /// Whether fading is finished. + Bool fade_fin; + + // Frame-opacity-related members /// Current window frame opacity. Affected by window opacity. double frame_opacity; /// Opacity of current frame_alpha_pict. opacity_t frame_opacity_cur; /// Alpha mask Picture to render window frame with opacity. Picture frame_alpha_pict; + /// Frame widths. Determined by client window attributes. + unsigned int left_width, right_width, top_width, bottom_width; + // Shadow-related members /// Whether a window has shadow. Affected by window type. Bool shadow; /// Opacity of the shadow. Affected by window opacity and frame opacity. @@ -146,6 +158,7 @@ typedef struct _win { /// shadow opacity. Picture shadow_pict; + // Dim-related members /// Whether the window is to be dimmed. Bool dim; @@ -165,16 +178,6 @@ typedef struct _conv { double *data; } conv; -typedef struct _fade { - struct _fade *next; - win *w; - double cur; - double finish; - double step; - void (*callback) (Display *dpy, win *w); - Display *dpy; -} fade; - typedef enum { WIN_EVMODE_UNKNOWN, WIN_EVMODE_FRAME, @@ -217,16 +220,30 @@ normalize_i_range(int i, int min, int max) { return i; } +/** + * Normalize a double value to a specific range. + * + * @param d double value to normalize + * @param min minimal value + * @param max maximum value + * @return normalized value + */ +static inline double +normalize_d_range(double d, double min, double max) { + if (d > max) return max; + if (d < min) return min; + return d; +} + /** * Normalize a double value to 0.\ 0 - 1.\ 0. * * @param d double value to normalize + * @return normalized value */ static inline double normalize_d(double d) { - if (d > 1.0) return 1.0; - if (d < 0.0) return 0.0; - return d; + return normalize_d_range(d, 0.0, 1.0); } /** @@ -388,32 +405,33 @@ win_get_children(Display *dpy, Window w, return True; } -static int +static unsigned long get_time_in_milliseconds(void); -static fade * -find_fade(win *w); - -static void -dequeue_fade(Display *dpy, fade *f); - -static void -cleanup_fade(Display *dpy, win *w); +static int +fade_timeout(void); static void -enqueue_fade(Display *dpy, fade *f); +run_fade(Display *dpy, win *w, unsigned steps); static void -set_fade(Display *dpy, win *w, double start, - double finish, double step, - void(*callback) (Display *dpy, win *w), - Bool exec_callback, Bool override); +set_fade_callback(Display *dpy, win *w, + void (*callback) (Display *dpy, win *w), Bool exec_callback); -static int -fade_timeout(void); +/** + * Execute fade callback of a window if fading finished. + */ +static inline void +check_fade_fin(Display *dpy, win *w) { + if (w->fade_fin) { + set_fade_callback(dpy, w, NULL, True); + w->fade_fin = False; + } +} static void -run_fades(Display *dpy); +set_fade_callback(Display *dpy, win *w, + void (*callback) (Display *dpy, win *w), Bool exec_callback); static double gaussian(double r, double x, double y); @@ -476,8 +494,11 @@ get_frame_extents(Display *dpy, Window w, unsigned int *top, unsigned int *bottom); +static win * +paint_preprocess(Display *dpy, win *list); + static void -paint_all(Display *dpy, XserverRegion region); +paint_all(Display *dpy, XserverRegion region, win *t); static void add_damage(Display *dpy, XserverRegion damage); @@ -516,15 +537,15 @@ get_opacity_percent(Display *dpy, win *w); static void determine_mode(Display *dpy, win *w); -static void -set_opacity(Display *dpy, win *w, opacity_t opacity); - static void calc_opacity(Display *dpy, win *w, Bool refetch_prop); static void calc_dim(Display *dpy, win *w); +static void +determine_fade(Display *dpy, win *w); + static void determine_shadow(Display *dpy, win *w); -- cgit v1.2.1