[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 414/473: Add support for transparent background.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:59:44 CET 2015
This is an automated email from the git hooks/post-receive script.
gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.
commit 5f32cfa955da4d92520cf4cadaa766ce98981e2e
Author: Graeme Gott <graeme at gottcode.org>
Date: Sat Dec 6 19:40:32 2014 -0500
Add support for transparent background.
---
panel-plugin/settings.cpp | 5 +++-
panel-plugin/settings.h | 1 +
panel-plugin/window.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++-
panel-plugin/window.h | 3 +++
4 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/panel-plugin/settings.cpp b/panel-plugin/settings.cpp
index e2fd2aa..f7d2526 100644
--- a/panel-plugin/settings.cpp
+++ b/panel-plugin/settings.cpp
@@ -105,7 +105,8 @@ Settings::Settings() :
position_categories_alternate(false),
menu_width(400),
- menu_height(500)
+ menu_height(500),
+ menu_opacity(100)
{
favorites.push_back("exo-terminal-emulator.desktop");
favorites.push_back("exo-file-manager.desktop");
@@ -186,6 +187,7 @@ void Settings::load(char* file)
menu_width = std::max(300, xfce_rc_read_int_entry(rc, "menu-width", menu_width));
menu_height = std::max(400, xfce_rc_read_int_entry(rc, "menu-height", menu_height));
+ menu_opacity = std::min(100, std::max(0, xfce_rc_read_int_entry(rc, "menu-opacity", menu_height)));
for (int i = 0; i < CountCommands; ++i)
{
@@ -281,6 +283,7 @@ void Settings::save(char* file)
xfce_rc_write_int_entry(rc, "menu-width", menu_width);
xfce_rc_write_int_entry(rc, "menu-height", menu_height);
+ xfce_rc_write_int_entry(rc, "menu-opacity", menu_opacity);
for (int i = 0; i < CountCommands; ++i)
{
diff --git a/panel-plugin/settings.h b/panel-plugin/settings.h
index 88f119d..bd24f96 100644
--- a/panel-plugin/settings.h
+++ b/panel-plugin/settings.h
@@ -97,6 +97,7 @@ public:
int menu_width;
int menu_height;
+ int menu_opacity;
friend class Plugin;
};
diff --git a/panel-plugin/window.cpp b/panel-plugin/window.cpp
index bc1c793..12ccc7a 100644
--- a/panel-plugin/window.cpp
+++ b/panel-plugin/window.cpp
@@ -43,7 +43,8 @@ Window::Window() :
m_layout_left(true),
m_layout_bottom(true),
m_layout_search_alternate(false),
- m_layout_commands_alternate(false)
+ m_layout_commands_alternate(false),
+ m_supports_alpha(false)
{
m_geometry.x = 0;
m_geometry.y = 0;
@@ -224,6 +225,14 @@ Window::Window() :
// Resize to last known size
gtk_window_set_default_size(m_window, m_geometry.width, m_geometry.height);
+ // Handle transparency
+ gtk_widget_set_app_paintable(GTK_WIDGET(m_sidebar_box), true);
+ g_signal_connect_slot(m_sidebar_box, "expose-event", &Window::on_expose_event, this);
+ gtk_widget_set_app_paintable(GTK_WIDGET(m_window), true);
+ g_signal_connect_slot(m_window, "expose-event", &Window::on_expose_event, this);
+ g_signal_connect_slot(m_window, "screen-changed", &Window::on_screen_changed_event, this);
+ on_screen_changed_event(GTK_WIDGET(m_window), NULL);
+
g_object_ref_sink(m_window);
// Start loading applications immediately
@@ -799,6 +808,55 @@ gboolean Window::on_configure_event(GtkWidget*, GdkEvent* event)
//-----------------------------------------------------------------------------
+void Window::on_screen_changed_event(GtkWidget* widget, GdkScreen*)
+{
+ GdkScreen* screen = gtk_widget_get_screen(widget);
+ GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen);
+ if (!colormap)
+ {
+ colormap = gdk_screen_get_rgb_colormap(screen);
+ }
+ else
+ {
+ m_supports_alpha = true;
+ }
+ gtk_widget_set_colormap(widget, colormap);
+}
+
+//-----------------------------------------------------------------------------
+
+gboolean Window::on_expose_event(GtkWidget* widget, GdkEventExpose*)
+{
+ if (!gtk_widget_get_realized(widget))
+ {
+ gtk_widget_realize(widget);
+ }
+
+ GtkStyle* style = gtk_widget_get_style(widget);
+ if (style == NULL)
+ {
+ return false;
+ }
+ GdkColor color = style->bg[GTK_STATE_NORMAL];
+
+ cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(widget));
+ if (m_supports_alpha)
+ {
+ cairo_set_source_rgba(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0, wm_settings->menu_opacity / 100.0);
+ }
+ else
+ {
+ cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
+ }
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+
void Window::favorites_toggled()
{
m_favorites->reset_selection();
diff --git a/panel-plugin/window.h b/panel-plugin/window.h
index fc88056..e732bf4 100644
--- a/panel-plugin/window.h
+++ b/panel-plugin/window.h
@@ -81,6 +81,8 @@ private:
gboolean on_key_press_event_after(GtkWidget* widget, GdkEvent* event);
gboolean on_map_event(GtkWidget*, GdkEvent*);
gboolean on_configure_event(GtkWidget*, GdkEvent* event);
+ void on_screen_changed_event(GtkWidget* widget, GdkScreen* old_screen);
+ gboolean on_expose_event(GtkWidget* widget, GdkEventExpose* event);
void favorites_toggled();
void recent_toggled();
void category_toggled();
@@ -128,6 +130,7 @@ private:
bool m_layout_bottom;
bool m_layout_search_alternate;
bool m_layout_commands_alternate;
+ bool m_supports_alpha;
};
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list