Move struct win to win.h

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-10-21 03:10:12 +01:00
parent 0686300013
commit 1f95c74a68
5 changed files with 288 additions and 267 deletions

View File

@ -167,7 +167,9 @@
#include "xrescheck.h" #include "xrescheck.h"
#endif #endif
// FIXME This list of includes should get shorter
#include "types.h" #include "types.h"
#include "win.h"
#include "x.h" #include "x.h"
#include "region.h" #include "region.h"
@ -224,34 +226,8 @@
typedef long time_ms_t; typedef long time_ms_t;
typedef struct _c2_lptr c2_lptr_t; typedef struct _c2_lptr c2_lptr_t;
typedef enum {
WINTYPE_UNKNOWN,
WINTYPE_DESKTOP,
WINTYPE_DOCK,
WINTYPE_TOOLBAR,
WINTYPE_MENU,
WINTYPE_UTILITY,
WINTYPE_SPLASH,
WINTYPE_DIALOG,
WINTYPE_NORMAL,
WINTYPE_DROPDOWN_MENU,
WINTYPE_POPUP_MENU,
WINTYPE_TOOLTIP,
WINTYPE_NOTIFY,
WINTYPE_COMBO,
WINTYPE_DND,
NUM_WINTYPES
} wintype_t;
// Or use cmemzero(). // Or use cmemzero().
/// Enumeration type of window painting mode.
typedef enum {
WMODE_TRANS, // The window body is (potentially) transparent
WMODE_FRAME_TRANS, // The window body is opaque, but the frame is not
WMODE_SOLID, // The window is opaque including the frame
} winmode_t;
/// Structure representing needed window updates. /// Structure representing needed window updates.
typedef struct { typedef struct {
bool shadow : 1; bool shadow : 1;
@ -428,17 +404,6 @@ typedef struct {
GLint unifm_factor_center; GLint unifm_factor_center;
} glx_blur_pass_t; } glx_blur_pass_t;
typedef struct {
/// Framebuffer used for blurring.
GLuint fbo;
/// Textures used for blurring.
GLuint textures[2];
/// Width of the textures.
int width;
/// Height of the textures.
int height;
} glx_blur_cache_t;
typedef struct { typedef struct {
/// GLSL program. /// GLSL program.
GLuint prog; GLuint prog;
@ -462,12 +427,6 @@ typedef struct {
typedef uint32_t glx_prog_main_t; typedef uint32_t glx_prog_main_t;
#endif #endif
typedef struct {
xcb_pixmap_t pixmap;
xcb_render_picture_t pict;
glx_texture_t *ptex;
} paint_t;
#define PAINT_INIT { .pixmap = None, .pict = None } #define PAINT_INIT { .pixmap = None, .pict = None }
typedef struct conv { typedef struct conv {
@ -483,7 +442,6 @@ typedef struct _latom {
#define REG_DATA_INIT { NULL, 0 } #define REG_DATA_INIT { NULL, 0 }
typedef struct win win;
typedef struct ev_session_timer ev_session_timer; typedef struct ev_session_timer ev_session_timer;
typedef struct ev_session_idle ev_session_idle; typedef struct ev_session_idle ev_session_idle;
typedef struct ev_session_prepare ev_session_prepare; typedef struct ev_session_prepare ev_session_prepare;
@ -1004,201 +962,6 @@ typedef struct session {
#endif #endif
} session_t; } session_t;
/**
* About coordinate systems
*
* In general, X is the horizontal axis, Y is the vertical axis.
* X goes from left to right, Y goes downwards.
*
* Global: the origin is the top left corner of the Xorg screen.
* Local: the origin is the top left corner of the window, including border.
*/
/// Structure representing a top-level window compton manages.
struct win {
/// Pointer to the next lower window in window stack.
win *next;
/// Pointer to the next higher window to paint.
win *prev_trans;
// Core members
/// ID of the top-level frame window.
Window id;
/// Window attributes.
xcb_get_window_attributes_reply_t a;
xcb_get_geometry_reply_t g;
#ifdef CONFIG_XINERAMA
/// Xinerama screen this window is on.
int xinerama_scr;
#endif
/// Window visual pict format;
xcb_render_pictforminfo_t *pictfmt;
/// Window painting mode.
winmode_t mode;
/// Whether the window has been damaged at least once.
bool ever_damaged;
#ifdef CONFIG_XSYNC
/// X Sync fence of drawable.
XSyncFence fence;
#endif
/// Whether the window was damaged after last paint.
bool pixmap_damaged;
/// Damage of the window.
xcb_damage_damage_t damage;
/// Paint info of the window.
paint_t paint;
/// Bounding shape of the window. In local coordinates.
/// See above about coordinate systems.
region_t bounding_shape;
/// Window flags. Definitions above.
int_fast16_t flags;
/// Whether there's a pending <code>ConfigureNotify</code> happening
/// when the window is unmapped.
bool need_configure;
/// Queued <code>ConfigureNotify</code> when the window is unmapped.
xcb_configure_notify_event_t queue_configure;
/// The region of screen that will be obscured when windows above is painted.
/// We use this to reduce the pixels that needed to be paint when painting
/// this window and anything underneath. Depends on window frame
/// opacity state, window geometry, window mapped/unmapped state,
/// window mode of the windows above. DOES NOT INCLUDE the body of THIS WINDOW.
/// NULL means reg_ignore has not been calculated for this window.
rc_region_t *reg_ignore;
/// Whether the reg_ignore of all windows beneath this window are valid
bool reg_ignore_valid;
/// Cached width/height of the window including border.
int widthb, heightb;
/// Whether the window has been destroyed.
bool destroyed;
/// Whether the window is bounding-shaped.
bool bounding_shaped;
/// Whether the window just have rounded corners.
bool rounded_corners;
/// Whether this window is to be painted.
bool to_paint;
/// Whether the window is painting excluded.
bool paint_excluded;
/// Whether the window is unredirect-if-possible excluded.
bool unredir_if_possible_excluded;
/// Whether this window is in open/close state.
bool in_openclose;
// Client window related members
/// ID of the top-level client window of the window.
Window client_win;
/// Type of the window.
wintype_t window_type;
/// Whether it looks like a WM window. We consider a window WM window if
/// it does not have a decedent with WM_STATE and it is not override-
/// redirected itself.
bool wmwin;
/// Leader window ID of the window.
Window leader;
/// Cached topmost window ID of the window.
Window cache_leader;
// Focus-related members
/// Whether the window is to be considered focused.
bool focused;
/// Override value of window focus state. Set by D-Bus method calls.
switch_t focused_force;
// Blacklist related members
/// Name of the window.
char *name;
/// Window instance class of the window.
char *class_instance;
/// Window general class of the window.
char *class_general;
/// <code>WM_WINDOW_ROLE</code> value of the window.
char *role;
const c2_lptr_t *cache_sblst;
const c2_lptr_t *cache_fblst;
const c2_lptr_t *cache_fcblst;
const c2_lptr_t *cache_ivclst;
const c2_lptr_t *cache_bbblst;
const c2_lptr_t *cache_oparule;
const c2_lptr_t *cache_pblst;
const c2_lptr_t *cache_uipblst;
// Opacity-related members
/// Current window opacity.
opacity_t opacity;
/// Target window opacity.
opacity_t opacity_tgt;
/// true if window (or client window, for broken window managers
/// not transferring client window's _NET_WM_OPACITY value) has opacity prop
bool has_opacity_prop;
/// Cached value of opacity window attribute.
opacity_t opacity_prop;
/// true if opacity is set by some rules
bool opacity_is_set;
/// Last window opacity value we set.
opacity_t opacity_set;
// Fading-related members
/// Do not fade if it's false. Change on window type change.
/// Used by fading blacklist in the future.
bool fade;
/// Fade state on last paint.
bool fade_last;
/// Override value of window fade state. Set by D-Bus method calls.
switch_t fade_force;
/// Callback to be called after fading completed.
void (*fade_callback) (session_t *ps, win **w);
// Frame-opacity-related members
/// Current window frame opacity. Affected by window opacity.
double frame_opacity;
/// Frame extents. Acquired from _NET_FRAME_EXTENTS.
margin_t frame_extents;
// Shadow-related members
/// Whether a window has shadow. Calculated.
bool shadow;
/// Shadow state on last paint.
bool shadow_last;
/// Override value of window shadow state. Set by D-Bus method calls.
switch_t shadow_force;
/// Opacity of the shadow. Affected by window opacity and frame opacity.
double shadow_opacity;
/// X offset of shadow. Affected by commandline argument.
int shadow_dx;
/// Y offset of shadow. Affected by commandline argument.
int shadow_dy;
/// Width of shadow. Affected by window size and commandline argument.
int shadow_width;
/// Height of shadow. Affected by window size and commandline argument.
int shadow_height;
/// Picture to render shadow. Affected by window size.
paint_t shadow_paint;
/// The value of _COMPTON_SHADOW attribute of the window. Below 0 for
/// none.
long prop_shadow;
// Dim-related members
/// Whether the window is to be dimmed.
bool dim;
/// Whether to invert window color.
bool invert_color;
/// Color inversion state on last paint.
bool invert_color_last;
/// Override value of window color inversion state. Set by D-Bus method
/// calls.
switch_t invert_color_force;
/// Whether to blur window background.
bool blur_background;
/// Background state on last paint.
bool blur_background_last;
#ifdef CONFIG_OPENGL
/// Textures and FBO background blur use.
glx_blur_cache_t glx_blur_cache;
#endif
};
/// Temporary structure used for communication between /// Temporary structure used for communication between
/// <code>get_cfg()</code> and <code>parse_config()</code>. /// <code>get_cfg()</code> and <code>parse_config()</code>.
struct options_tmp { struct options_tmp {

View File

@ -30,6 +30,7 @@
#include "opengl.h" // XXX clean up #include "opengl.h" // XXX clean up
#endif #endif
#include "common.h" #include "common.h"
#include "win.h"
#include "x.h" #include "x.h"
#include "c2.h" #include "c2.h"
@ -321,30 +322,6 @@ win_ev_stop(session_t *ps, win *w) {
} }
} }
/**
* Check whether a window has WM frames.
*/
static inline bool __attribute__((pure))
win_has_frame(const win *w) {
return w->g.border_width
|| w->frame_extents.top || w->frame_extents.left
|| w->frame_extents.right || w->frame_extents.bottom;
}
/**
* Calculate the extents of the frame of the given window based on EWMH
* _NET_FRAME_EXTENTS and the X window border width.
*/
static inline margin_t __attribute__((pure))
win_calc_frame_extents(session_t *ps, const win *w) {
margin_t result = w->frame_extents;
result.top = max_i(result.top, w->g.border_width);
result.left = max_i(result.left, w->g.border_width);
result.bottom = max_i(result.bottom, w->g.border_width);
result.right = max_i(result.right, w->g.border_width);
return result;
}
/** /**
* Dump an drawable's info. * Dump an drawable's info.
*/ */

View File

@ -10,6 +10,7 @@
*/ */
#include "dbus.h" #include "dbus.h"
#include "win.h"
static DBusHandlerResult static DBusHandlerResult
cdbus_process(DBusConnection *conn, DBusMessage *m, void *); cdbus_process(DBusConnection *conn, DBusMessage *m, void *);

View File

@ -1,6 +1,8 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2018 Yuxuan Shui <yshuiv7@gmail.com> // Copyright (c) 2018 Yuxuan Shui <yshuiv7@gmail.com>
#pragma once
/// Some common types /// Some common types
#include <stdint.h> #include <stdint.h>

286
src/win.h
View File

@ -1,15 +1,269 @@
#pragma once
#include <stdbool.h>
#include <X11/Xlib.h>
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2011-2013, Christopher Jeffrey // Copyright (c) 2011-2013, Christopher Jeffrey
// Copyright (c) 2013 Richard Grenville <pyxlcy@gmail.com> // Copyright (c) 2013 Richard Grenville <pyxlcy@gmail.com>
#pragma once
#include <stdbool.h>
#include <X11/Xlib.h>
#ifdef CONFIG_XSYNC
#include <X11/extensions/sync.h>
#endif
#include <xcb/damage.h>
// FIXME shouldn't need this
#ifdef CONFIG_OPENGL
#include <GL/glx.h>
#endif
#include "x.h" #include "x.h"
#include "types.h"
#include "c2.h"
#include "utils.h"
typedef struct session session_t; typedef struct session session_t;
typedef struct win win; typedef struct _glx_texture glx_texture_t;
// FIXME not the best place for this type
typedef struct {
xcb_pixmap_t pixmap;
xcb_render_picture_t pict;
glx_texture_t *ptex;
} paint_t;
// FIXME this type should be in opengl.h
// it is very unideal for it to be here
typedef struct {
/// Framebuffer used for blurring.
GLuint fbo;
/// Textures used for blurring.
GLuint textures[2];
/// Width of the textures.
int width;
/// Height of the textures.
int height;
} glx_blur_cache_t;
typedef enum {
WINTYPE_UNKNOWN,
WINTYPE_DESKTOP,
WINTYPE_DOCK,
WINTYPE_TOOLBAR,
WINTYPE_MENU,
WINTYPE_UTILITY,
WINTYPE_SPLASH,
WINTYPE_DIALOG,
WINTYPE_NORMAL,
WINTYPE_DROPDOWN_MENU,
WINTYPE_POPUP_MENU,
WINTYPE_TOOLTIP,
WINTYPE_NOTIFY,
WINTYPE_COMBO,
WINTYPE_DND,
NUM_WINTYPES
} wintype_t;
/// Enumeration type of window painting mode.
typedef enum {
WMODE_TRANS, // The window body is (potentially) transparent
WMODE_FRAME_TRANS, // The window body is opaque, but the frame is not
WMODE_SOLID, // The window is opaque including the frame
} winmode_t;
/**
* About coordinate systems
*
* In general, X is the horizontal axis, Y is the vertical axis.
* X goes from left to right, Y goes downwards.
*
* Global: the origin is the top left corner of the Xorg screen.
* Local: the origin is the top left corner of the window, including border.
*/
/// Structure representing a top-level window compton manages.
typedef struct win win;
struct win {
/// Pointer to the next lower window in window stack.
win *next;
/// Pointer to the next higher window to paint.
win *prev_trans;
// Core members
/// ID of the top-level frame window.
Window id;
/// Window attributes.
xcb_get_window_attributes_reply_t a;
xcb_get_geometry_reply_t g;
#ifdef CONFIG_XINERAMA
/// Xinerama screen this window is on.
int xinerama_scr;
#endif
/// Window visual pict format;
xcb_render_pictforminfo_t *pictfmt;
/// Window painting mode.
winmode_t mode;
/// Whether the window has been damaged at least once.
bool ever_damaged;
#ifdef CONFIG_XSYNC
/// X Sync fence of drawable.
XSyncFence fence;
#endif
/// Whether the window was damaged after last paint.
bool pixmap_damaged;
/// Damage of the window.
xcb_damage_damage_t damage;
/// Paint info of the window.
paint_t paint;
/// Bounding shape of the window. In local coordinates.
/// See above about coordinate systems.
region_t bounding_shape;
/// Window flags. Definitions above.
int_fast16_t flags;
/// Whether there's a pending <code>ConfigureNotify</code> happening
/// when the window is unmapped.
bool need_configure;
/// Queued <code>ConfigureNotify</code> when the window is unmapped.
xcb_configure_notify_event_t queue_configure;
/// The region of screen that will be obscured when windows above is painted.
/// We use this to reduce the pixels that needed to be paint when painting
/// this window and anything underneath. Depends on window frame
/// opacity state, window geometry, window mapped/unmapped state,
/// window mode of the windows above. DOES NOT INCLUDE the body of THIS WINDOW.
/// NULL means reg_ignore has not been calculated for this window.
rc_region_t *reg_ignore;
/// Whether the reg_ignore of all windows beneath this window are valid
bool reg_ignore_valid;
/// Cached width/height of the window including border.
int widthb, heightb;
/// Whether the window has been destroyed.
bool destroyed;
/// Whether the window is bounding-shaped.
bool bounding_shaped;
/// Whether the window just have rounded corners.
bool rounded_corners;
/// Whether this window is to be painted.
bool to_paint;
/// Whether the window is painting excluded.
bool paint_excluded;
/// Whether the window is unredirect-if-possible excluded.
bool unredir_if_possible_excluded;
/// Whether this window is in open/close state.
bool in_openclose;
// Client window related members
/// ID of the top-level client window of the window.
Window client_win;
/// Type of the window.
wintype_t window_type;
/// Whether it looks like a WM window. We consider a window WM window if
/// it does not have a decedent with WM_STATE and it is not override-
/// redirected itself.
bool wmwin;
/// Leader window ID of the window.
Window leader;
/// Cached topmost window ID of the window.
Window cache_leader;
// Focus-related members
/// Whether the window is to be considered focused.
bool focused;
/// Override value of window focus state. Set by D-Bus method calls.
switch_t focused_force;
// Blacklist related members
/// Name of the window.
char *name;
/// Window instance class of the window.
char *class_instance;
/// Window general class of the window.
char *class_general;
/// <code>WM_WINDOW_ROLE</code> value of the window.
char *role;
const c2_lptr_t *cache_sblst;
const c2_lptr_t *cache_fblst;
const c2_lptr_t *cache_fcblst;
const c2_lptr_t *cache_ivclst;
const c2_lptr_t *cache_bbblst;
const c2_lptr_t *cache_oparule;
const c2_lptr_t *cache_pblst;
const c2_lptr_t *cache_uipblst;
// Opacity-related members
/// Current window opacity.
opacity_t opacity;
/// Target window opacity.
opacity_t opacity_tgt;
/// true if window (or client window, for broken window managers
/// not transferring client window's _NET_WM_OPACITY value) has opacity prop
bool has_opacity_prop;
/// Cached value of opacity window attribute.
opacity_t opacity_prop;
/// true if opacity is set by some rules
bool opacity_is_set;
/// Last window opacity value we set.
opacity_t opacity_set;
// Fading-related members
/// Do not fade if it's false. Change on window type change.
/// Used by fading blacklist in the future.
bool fade;
/// Fade state on last paint.
bool fade_last;
/// Override value of window fade state. Set by D-Bus method calls.
switch_t fade_force;
/// Callback to be called after fading completed.
void (*fade_callback) (session_t *ps, win **w);
// Frame-opacity-related members
/// Current window frame opacity. Affected by window opacity.
double frame_opacity;
/// Frame extents. Acquired from _NET_FRAME_EXTENTS.
margin_t frame_extents;
// Shadow-related members
/// Whether a window has shadow. Calculated.
bool shadow;
/// Shadow state on last paint.
bool shadow_last;
/// Override value of window shadow state. Set by D-Bus method calls.
switch_t shadow_force;
/// Opacity of the shadow. Affected by window opacity and frame opacity.
double shadow_opacity;
/// X offset of shadow. Affected by commandline argument.
int shadow_dx;
/// Y offset of shadow. Affected by commandline argument.
int shadow_dy;
/// Width of shadow. Affected by window size and commandline argument.
int shadow_width;
/// Height of shadow. Affected by window size and commandline argument.
int shadow_height;
/// Picture to render shadow. Affected by window size.
paint_t shadow_paint;
/// The value of _COMPTON_SHADOW attribute of the window. Below 0 for
/// none.
long prop_shadow;
// Dim-related members
/// Whether the window is to be dimmed.
bool dim;
/// Whether to invert window color.
bool invert_color;
/// Color inversion state on last paint.
bool invert_color_last;
/// Override value of window color inversion state. Set by D-Bus method
/// calls.
switch_t invert_color_force;
/// Whether to blur window background.
bool blur_background;
/// Background state on last paint.
bool blur_background_last;
#ifdef CONFIG_OPENGL
/// Textures and FBO background blur use.
glx_blur_cache_t glx_blur_cache;
#endif
};
int win_get_name(session_t *ps, win *w); int win_get_name(session_t *ps, win *w);
int win_get_role(session_t *ps, win *w); int win_get_role(session_t *ps, win *w);
@ -107,3 +361,27 @@ win_get_bounding_shape_global_by_val(win *w) {
pixman_region32_translate(&ret, w->g.x, w->g.y); pixman_region32_translate(&ret, w->g.x, w->g.y);
return ret; return ret;
} }
/**
* Calculate the extents of the frame of the given window based on EWMH
* _NET_FRAME_EXTENTS and the X window border width.
*/
static inline margin_t __attribute__((pure))
win_calc_frame_extents(session_t *ps, const win *w) {
margin_t result = w->frame_extents;
result.top = max_i(result.top, w->g.border_width);
result.left = max_i(result.left, w->g.border_width);
result.bottom = max_i(result.bottom, w->g.border_width);
result.right = max_i(result.right, w->g.border_width);
return result;
}
/**
* Check whether a window has WM frames.
*/
static inline bool __attribute__((pure))
win_has_frame(const win *w) {
return w->g.border_width
|| w->frame_extents.top || w->frame_extents.left
|| w->frame_extents.right || w->frame_extents.bottom;
}