Skip to content

Different Shadow Color for Focused Window #13

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

Open
wants to merge 7 commits into
base: dual_kawase
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ uninstall:
@rm -f "$(DESTDIR)$(BINDIR)/compton" "$(DESTDIR)$(BINDIR)/compton-trans"
@rm -f $(addprefix "$(DESTDIR)$(MANDIR)"/, compton.1 compton-trans.1)
@rm -f "$(DESTDIR)$(APPDIR)/compton.desktop"
@rm -f "/usr/share/icon/hicolor/48x48/apps/compton.png"
@rm -f "/usr/share/icons/hicolor/scaleable/apps/compton.png"
ifneq "$(DOCDIR)" ""
@rm -f $(addprefix "$(DESTDIR)$(DOCDIR)"/, README.md compton.sample.conf cdbus-driver.sh)
endif
Expand Down
3 changes: 3 additions & 0 deletions compton.sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ shadow-offset-y = -7;
# shadow-red = 0.0;
# shadow-green = 0.0;
# shadow-blue = 0.0;
# shadow-focused-red = 0.0;
# shadow-focused-green = 0.0;
# shadow-focused-blue = 0.0;
shadow-exclude = [
"name = 'Notification'",
"class_g = 'Conky'",
Expand Down
3 changes: 3 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
#define WFLAG_POS_CHANGE 0x0002
// Window opacity / dim state changed
#define WFLAG_OPCT_CHANGE 0x0004
#define WFLAG_FOCUS_CHANGE 0x0008

// === Types ===

Expand Down Expand Up @@ -644,6 +645,7 @@ typedef struct _options_t {
bool wintype_shadow[NUM_WINTYPES];
/// Red, green and blue tone of the shadow.
double shadow_red, shadow_green, shadow_blue;
double shadow_focused_red, shadow_focused_green, shadow_focused_blue;
int shadow_radius;
int shadow_offset_x, shadow_offset_y;
double shadow_opacity;
Expand Down Expand Up @@ -921,6 +923,7 @@ typedef struct _session_t {
Picture black_picture;
/// 1x1 Picture of the shadow color.
Picture cshadow_picture;
Picture cshadow_picture_focused;
/// 1x1 white Picture.
Picture white_picture;
/// Gaussian map of shadow.
Expand Down
47 changes: 44 additions & 3 deletions src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ win_build_shadow(session_t *ps, win *w, double opacity) {
const int width = w->widthb;
const int height = w->heightb;

Picture *shadow_to_apply;

XImage *shadow_image = NULL;
Pixmap shadow_pixmap = None, shadow_pixmap_argb = None;
Picture shadow_picture = None, shadow_picture_argb = None;
Expand Down Expand Up @@ -482,7 +484,14 @@ win_build_shadow(session_t *ps, win *w, double opacity) {

XPutImage(ps->dpy, shadow_pixmap, gc, shadow_image, 0, 0, 0, 0,
shadow_image->width, shadow_image->height);
XRenderComposite(ps->dpy, PictOpSrc, ps->cshadow_picture, shadow_picture,

if (win_is_focused_real(ps, w)) {
shadow_to_apply = &ps->cshadow_picture_focused;
} else {
shadow_to_apply = &ps->cshadow_picture;
}

XRenderComposite(ps->dpy, PictOpSrc, *shadow_to_apply, shadow_picture,
shadow_picture_argb, 0, 0, 0, 0, 0, 0,
shadow_image->width, shadow_image->height);

Expand Down Expand Up @@ -1110,7 +1119,7 @@ paint_preprocess(session_t *ps, win *list) {
// Data expiration
{
// Remove built shadow if needed
if (w->flags & WFLAG_SIZE_CHANGE)
if (w->flags & (WFLAG_SIZE_CHANGE | WFLAG_FOCUS_CHANGE))
free_paint(ps, &w->shadow_paint);

// Destroy reg_ignore on all windows if they should expire
Expand Down Expand Up @@ -1309,6 +1318,7 @@ static inline void
win_paint_shadow(session_t *ps, win *w,
XserverRegion reg_paint, const reg_data_t *pcache_reg) {
// Bind shadow pixmap to GLX texture if needed

paint_bind_tex(ps, &w->shadow_paint, 0, 0, 32, false);

if (!paint_isvalid(ps, &w->shadow_paint)) {
Expand Down Expand Up @@ -1748,6 +1758,7 @@ rebuild_shadow_exclude_reg(session_t *ps) {
ps->shadow_exclude_reg = rect_to_reg(ps, &rect);
}


static void
paint_all(session_t *ps, XserverRegion region, XserverRegion region_real, win *t) {
if (!region_real)
Expand Down Expand Up @@ -3469,6 +3480,7 @@ win_update_focused(session_t *ps, win *w) {
// options depend on the output value of win_is_focused_real() instead of
// w->focused
w->flags |= WFLAG_OPCT_CHANGE;
w->flags |= WFLAG_FOCUS_CHANGE;
}

/**
Expand Down Expand Up @@ -5040,7 +5052,7 @@ parse_matrix(session_t *ps, const char *src, const char **endptr) {
int wid = 0, hei = 0;
const char *pc = NULL;
XFixed *matrix = NULL;

// Get matrix width and height
{
double val = 0.0;
Expand Down Expand Up @@ -5538,6 +5550,14 @@ parse_config(session_t *ps, struct options_tmp *pcfgtmp) {
config_lookup_float(&cfg, "shadow-green", &ps->o.shadow_green);
// --shadow-blue
config_lookup_float(&cfg, "shadow-blue", &ps->o.shadow_blue);

// --shadow-focused-red
config_lookup_float(&cfg, "shadow-focused-red", &ps->o.shadow_focused_red);
// --shadow-focused-green
config_lookup_float(&cfg, "shadow-focused-green", &ps->o.shadow_focused_green);
// --shadow-focused-blue
config_lookup_float(&cfg, "shadow-focused-blue", &ps->o.shadow_focused_blue);

// --shadow-exclude-reg
if (config_lookup_string(&cfg, "shadow-exclude-reg", &sval)
&& !parse_geometry(ps, sval, &ps->o.shadow_exclude_reg_geom))
Expand Down Expand Up @@ -5695,6 +5715,9 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
{ "shadow-red", required_argument, NULL, 257 },
{ "shadow-green", required_argument, NULL, 258 },
{ "shadow-blue", required_argument, NULL, 259 },
{ "shadow-focused-red", required_argument, NULL, 800 },
{ "shadow-focused-green", required_argument, NULL, 801 },
{ "shadow-focused-blue", required_argument, NULL, 802 },
{ "inactive-opacity-override", no_argument, NULL, 260 },
{ "inactive-dim", required_argument, NULL, 261 },
{ "mark-wmwin-focused", no_argument, NULL, 262 },
Expand Down Expand Up @@ -5893,14 +5916,23 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
// --shadow-red
ps->o.shadow_red = atof(optarg);
break;
case 800:
ps->o.shadow_focused_red = atof(optarg);
break;
case 258:
// --shadow-green
ps->o.shadow_green = atof(optarg);
break;
case 801:
ps->o.shadow_focused_green = atof(optarg);
break;
case 259:
// --shadow-blue
ps->o.shadow_blue = atof(optarg);
break;
case 802:
ps->o.shadow_focused_blue = atof(optarg);
break;
P_CASEBOOL(260, inactive_opacity_override);
case 261:
// --inactive-dim
Expand Down Expand Up @@ -6046,6 +6078,9 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
ps->o.shadow_red = normalize_d(ps->o.shadow_red);
ps->o.shadow_green = normalize_d(ps->o.shadow_green);
ps->o.shadow_blue = normalize_d(ps->o.shadow_blue);
ps->o.shadow_focused_red = normalize_d(ps->o.shadow_focused_red);
ps->o.shadow_focused_green = normalize_d(ps->o.shadow_focused_green);
ps->o.shadow_focused_blue = normalize_d(ps->o.shadow_focused_blue);
ps->o.inactive_dim = normalize_d(ps->o.inactive_dim);
ps->o.frame_opacity = normalize_d(ps->o.frame_opacity);
ps->o.shadow_opacity = normalize_d(ps->o.shadow_opacity);
Expand Down Expand Up @@ -7001,6 +7036,9 @@ session_init(session_t *ps_old, int argc, char **argv) {
.shadow_red = 0.0,
.shadow_green = 0.0,
.shadow_blue = 0.0,
.shadow_focused_red = 0.0,
.shadow_focused_green = 0.0,
.shadow_focused_blue = 0.0,
.shadow_radius = 12,
.shadow_offset_x = -15,
.shadow_offset_y = -15,
Expand Down Expand Up @@ -7399,6 +7437,9 @@ session_init(session_t *ps_old, int argc, char **argv) {
ps->o.shadow_red, ps->o.shadow_green, ps->o.shadow_blue);
}

ps->cshadow_picture_focused = solid_picture(ps, true, 1,
ps->o.shadow_focused_red, ps->o.shadow_focused_green, ps->o.shadow_focused_blue);

fds_insert(ps, ConnectionNumber(ps->dpy), POLLIN);
ps->tmout_unredir = timeout_insert(ps, ps->o.unredir_if_possible_delay,
tmout_unredir_callback, NULL);
Expand Down