Skip to content

Commit

Permalink
Add extra button configuration options
Browse files Browse the repository at this point in the history
This allows buttons to be a png image or different color, along with spacing and line thickness options.

Fixes #26.
  • Loading branch information
soreau committed Dec 25, 2024
1 parent b488614 commit 04310f4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 12 deletions.
35 changes: 35 additions & 0 deletions metadata/pixdecor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,41 @@
<_long>Color of the window titlebar text when it does not have focus.</_long>
<default>0.7 0.7 0.7 1.0</default>
</option>
<option name="button_color" type="color">
<_short>Button Color</_short>
<_long>Color of the minimize, maximize and close buttons.</_long>
<default>0.0 0.0 0.0 1.0</default>
</option>
<option name="button_line_thickness" type="double">
<_short>Button Line Thickness</_short>
<_long>The thickness used to draw the minimize, maximize and close button lines.</_long>
<default>0.7</default>
<min>0.0</min>
</option>
<option name="button_spacing" type="int">
<_short>Button Spacing</_short>
<_long>The space between each button.</_long>
<default>5</default>
<min>0</min>
</option>
<option name="button_minimize_image" type="string">
<_short>Button Minimize Image</_short>
<_long>The png image to use for the minimize button.</_long>
<default></default>
<hint>file</hint>
</option>
<option name="button_maximize_image" type="string">
<_short>Button Maximize Image</_short>
<_long>The png image to use for the maximize button.</_long>
<default></default>
<hint>file</hint>
</option>
<option name="button_close_image" type="string">
<_short>Button Close Image</_short>
<_long>The png image to use for the close button.</_long>
<default></default>
<hint>file</hint>
</option>
<option name="title_text_align" type="int">
<_short>Titlebar Text Alignment</_short>
<_long>Sets the alignment of the titlebar text.</_long>
Expand Down
13 changes: 10 additions & 3 deletions src/deco-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ decoration_layout_t::~decoration_layout_t()
wf::geometry_t decoration_layout_t::create_buttons(int width, int radius)
{
// read the string from settings; start at the colon and replace commas with spaces
wf::option_wrapper_t<int> button_spacing{"pixdecor/button_spacing"};
GSettings *settings = g_settings_new("org.gnome.desktop.wm.preferences");
gchar *b_layout = g_settings_get_string(settings, "button-layout");
gchar *ptr = b_layout + strlen(b_layout) - 1;
Expand Down Expand Up @@ -114,19 +115,25 @@ wf::geometry_t decoration_layout_t::create_buttons(int width, int radius)
}
}

int per_button = 2 * BUTTON_W_PAD + button_width;
int per_button = button_width;
int border = theme.get_border_size();
int button_padding = (theme.get_title_height() - button_height) / 2;
wf::geometry_t button_geometry = {
width - (maximized ? 0 : border),
width - (maximized ? 4 : border),
button_padding + border / 2 + (radius * 2),
button_width,
button_height,
};

bool first_button = true;
for (auto type : wf::reverse(buttons))
{
button_geometry.x -= per_button;
if (first_button)
{
per_button += button_spacing;
}
first_button = false;
this->layout_areas.push_back(std::make_unique<decoration_area_t>(
button_geometry, damage_callback, theme));
this->layout_areas.back()->as_button().set_button_type(type);
Expand All @@ -135,7 +142,7 @@ wf::geometry_t decoration_layout_t::create_buttons(int width, int radius)
int total_width = buttons.size() * per_button;

return {
button_geometry.x, maximized ? 0 : border + (radius * 2),
button_geometry.x, maximized ? 4 : border + (radius * 2),
total_width, theme.get_title_height()
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/deco-subsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
{
if (item->get_type() != wf::pixdecor::DECORATION_AREA_TITLE)
{
buttons_width += item->get_geometry().width + 2 * BUTTON_W_PAD;
buttons_width += item->get_geometry().width;
}
}

Expand Down
56 changes: 49 additions & 7 deletions src/deco-theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ wf::option_wrapper_t<wf::color_t> fg_color{"pixdecor/fg_color"};
wf::option_wrapper_t<wf::color_t> bg_color{"pixdecor/bg_color"};
wf::option_wrapper_t<wf::color_t> fg_text_color{"pixdecor/fg_text_color"};
wf::option_wrapper_t<wf::color_t> bg_text_color{"pixdecor/bg_text_color"};
wf::option_wrapper_t<std::string> button_minimize_image{"pixdecor/button_minimize_image"};
wf::option_wrapper_t<std::string> button_maximize_image{"pixdecor/button_maximize_image"};
wf::option_wrapper_t<std::string> button_close_image{"pixdecor/button_close_image"};
wf::option_wrapper_t<std::string> effect_type{"pixdecor/effect_type"};
wf::option_wrapper_t<std::string> overlay_engine{"pixdecor/overlay_engine"};
wf::option_wrapper_t<wf::color_t> effect_color{"pixdecor/effect_color"};
wf::option_wrapper_t<wf::color_t> button_color{"pixdecor/button_color"};
wf::option_wrapper_t<double> button_line_thickness{"pixdecor/button_line_thickness"};
/** Create a new theme with the default parameters */
decoration_theme_t::decoration_theme_t()
{
Expand Down Expand Up @@ -262,9 +266,43 @@ cairo_surface_t*decoration_theme_t::render_text(std::string text,
cairo_surface_t*decoration_theme_t::get_button_surface(button_type_t button,
const button_state_t& state, bool active) const
{
cairo_surface_t *button_surface = NULL;

switch (button)
{
case BUTTON_CLOSE:
if (!std::string(button_close_image).empty())
{
button_surface = cairo_image_surface_create_from_png(std::string(button_close_image).c_str());
}
break;

case BUTTON_TOGGLE_MAXIMIZE:
if (!std::string(button_maximize_image).empty())
{
button_surface = cairo_image_surface_create_from_png(std::string(button_maximize_image).c_str());
}
break;

case BUTTON_MINIMIZE:
if (!std::string(button_minimize_image).empty())
{
button_surface = cairo_image_surface_create_from_png(std::string(button_minimize_image).c_str());
}
break;
default:
break;
}

if (button_surface && cairo_surface_status(button_surface) == CAIRO_STATUS_SUCCESS)
{
return button_surface;
}

auto w = state.width;
auto h = state.height;
cairo_surface_t *button_surface = cairo_image_surface_create(

button_surface = cairo_image_surface_create(
CAIRO_FORMAT_ARGB32, w, h);

auto cr = cairo_create(button_surface);
Expand All @@ -279,12 +317,16 @@ cairo_surface_t*decoration_theme_t::get_button_surface(button_type_t button,

/** Draw the button */
cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
cairo_set_source_rgba(cr, 0, 0, 0, 1);
auto line_width = 3.0;
cairo_set_source_rgba(cr,
wf::color_t(button_color).r,
wf::color_t(button_color).g,
wf::color_t(button_color).b,
wf::color_t(button_color).a);
double line_width = button_line_thickness;
switch (button)
{
case BUTTON_CLOSE:
cairo_set_line_width(cr, line_width * state.border);
cairo_set_line_width(cr, line_width * state.border * 100.0);
cairo_move_to(cr, 1.0 * w / 4.0,
1.0 * h / 4.0);
cairo_line_to(cr, 3.0 * w / 4.0,
Expand All @@ -297,13 +339,13 @@ cairo_surface_t*decoration_theme_t::get_button_surface(button_type_t button,
break;

case BUTTON_TOGGLE_MAXIMIZE:
cairo_set_line_width(cr, line_width * state.border * 0.75);
cairo_set_line_width(cr, line_width * state.border * 100.0);
cairo_rectangle(cr, w / 4.0, h / 4.0, w / 2.0, h / 2.0);
cairo_stroke(cr);
break;

case BUTTON_MINIMIZE:
cairo_set_line_width(cr, line_width * state.border * 0.75);
cairo_set_line_width(cr, line_width * state.border * 100.0);
cairo_move_to(cr, 1.0 * w / 4.0,
3.0 * h / 4.0);
cairo_line_to(cr, 3.0 * w / 4.0,
Expand Down
1 change: 0 additions & 1 deletion src/deco-theme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#define MIN_RESIZE_HANDLE_SIZE 5
#define LARGE_ICON_THRESHOLD 20
#define MIN_BAR_HEIGHT 20
#define BUTTON_W_PAD 2

namespace wf
{
Expand Down
12 changes: 12 additions & 0 deletions src/decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class wayfire_pixdecor : public wf::plugin_interface_t
wf::option_wrapper_t<wf::color_t> bg_color{"pixdecor/bg_color"};
wf::option_wrapper_t<wf::color_t> fg_text_color{"pixdecor/fg_text_color"};
wf::option_wrapper_t<wf::color_t> bg_text_color{"pixdecor/bg_text_color"};
wf::option_wrapper_t<wf::color_t> button_color{"pixdecor/button_color"};
wf::option_wrapper_t<double> button_line_thickness{"pixdecor/button_line_thickness"};
wf::option_wrapper_t<int> button_spacing{"pixdecor/button_spacing"};
wf::option_wrapper_t<std::string> button_minimize_image{"pixdecor/button_minimize_image"};
wf::option_wrapper_t<std::string> button_maximize_image{"pixdecor/button_maximize_image"};
wf::option_wrapper_t<std::string> button_close_image{"pixdecor/button_close_image"};
wf::option_wrapper_t<std::string> ignore_views_string{"pixdecor/ignore_views"};
wf::option_wrapper_t<std::string> always_decorate_string{"pixdecor/always_decorate"};
wf::option_wrapper_t<std::string> effect_type{"pixdecor/effect_type"};
Expand Down Expand Up @@ -401,6 +407,12 @@ class wayfire_pixdecor : public wf::plugin_interface_t
effect_type.set_callback([=] {option_changed_cb(false, false);});
overlay_engine.set_callback([=] {option_changed_cb(true, false);});
effect_animate.set_callback([=] {option_changed_cb(false, false);});
button_color.set_callback([=] {recreate_frames();});
button_line_thickness.set_callback([=] {recreate_frames();});
button_spacing.set_callback([=] {recreate_frames();});
button_minimize_image.set_callback([=] {recreate_frames();});
button_maximize_image.set_callback([=] {recreate_frames();});
button_close_image.set_callback([=] {recreate_frames();});
title_text_align.set_callback([=]
{
for (auto& view : wf::get_core().get_all_views())
Expand Down

0 comments on commit 04310f4

Please sign in to comment.