Skip to content
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

skins: Made titlebar reflect focus status when using classic skins in gtk mode #159

Closed
wants to merge 9 commits into from
15 changes: 15 additions & 0 deletions src/skins/dock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,18 @@ void dock_change_scale (int old_scale, int new_scale)
}
}
}

bool dock_is_focused()
{
for (DockWindow & dw : windows)
{
if (dw.window==nullptr) continue;
if (dw.window->has_focus()) return true;
}
return false;
}

void refresh_dock_focus(){
for (DockWindow & dw : windows)
{ dw.window -> focus_refresh (); }
}
20 changes: 14 additions & 6 deletions src/skins/equalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,20 @@ static void equalizerwin_create_widgets ()

void EqWindow::draw (cairo_t * cr)
{
skin_draw_pixbuf (cr, SKIN_EQMAIN, 0, 0, 0, 0, 275, is_shaded () ? 14 : 116);

if (is_shaded ())
skin_draw_pixbuf (cr, SKIN_EQ_EX, 0, 0, 0, 0, 275, 14);
else
skin_draw_pixbuf (cr, SKIN_EQMAIN, 0, 134, 0, 0, 275, 14);
bool shaded = is_shaded ();
bool focused = dock_is_focused ();
int y_off = shaded ? 0 : 134;
if(!focused) y_off += 15;

SkinPixmapId tbar_id = shaded ? SKIN_EQ_EX : SKIN_EQMAIN;
skin_draw_pixbuf (cr, SKIN_EQMAIN, 0, 0, 0, 0, 275, shaded ? 14 : 116);

skin_draw_pixbuf (cr, tbar_id, 0, y_off, 0, 0, 275, 14);

if (m_is_drawn_focused!=focused){
queue_draw ();
m_is_drawn_focused=focused;
}
}

static void equalizerwin_create_window ()
Expand Down
7 changes: 5 additions & 2 deletions src/skins/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1149,9 +1149,12 @@ void MainWindow::draw (cairo_t * cr)
{
int width = is_shaded () ? MAINWIN_SHADED_WIDTH : skin.hints.mainwin_width;
int height = is_shaded () ? MAINWIN_SHADED_HEIGHT : skin.hints.mainwin_height;

bool focus = dock_is_focused ();
skin_draw_pixbuf (cr, SKIN_MAIN, 0, 0, 0, 0, width, height);
skin_draw_mainwin_titlebar (cr, is_shaded (), true);
skin_draw_mainwin_titlebar (cr, is_shaded (), focus);
if(focus!=m_is_drawn_focused){
m_is_drawn_focused=focus;
}
}

static void mainwin_create_window ()
Expand Down
9 changes: 7 additions & 2 deletions src/skins/playlistwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,16 @@ static void playlistwin_create_widgets ()

void PlWindow::draw (cairo_t * cr)
{
bool focus = dock_is_focused ();
if (is_shaded ())
skin_draw_playlistwin_shaded (cr, config.playlist_width, true);
skin_draw_playlistwin_shaded (cr, config.playlist_width, focus);
else
skin_draw_playlistwin_frame (cr, config.playlist_width,
config.playlist_height, true);
config.playlist_height, focus);
if (m_is_drawn_focused!=focus){
queue_draw ();
m_is_drawn_focused=focus;
}
}

static void playlistwin_create_window ()
Expand Down
17 changes: 16 additions & 1 deletion src/skins/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ Window::~Window ()

g_object_unref (m_normal);
g_object_unref (m_shaded);

}

static void focus_cb(GtkWidget *widget , GdkEventFocus *event , Window * win_ptr ){
win_ptr->focus_set(!! event->in);
refresh_dock_focus();
}
void Window::focus_refresh(){

if (m_is_drawn_focused==dock_is_focused()) return;
queue_draw();
m_is_drawn_focused=dock_is_focused();
}

Window::Window (int id, int * x, int * y, int w, int h, bool shaded) :
Expand Down Expand Up @@ -136,6 +148,9 @@ Window::Window (int id, int * x, int * y, int w, int h, bool shaded) :
gtk_container_add ((GtkContainer *) window, m_normal);

dock_add_window (id, this, x, y, w, h);

focus_hook_id1=g_signal_connect(G_OBJECT(window), "focus-out-event", G_CALLBACK(focus_cb), this);
focus_hook_id2=g_signal_connect(G_OBJECT(window), "focus-in-event", G_CALLBACK(focus_cb), this);
}

void Window::resize (int w, int h)
Expand Down Expand Up @@ -189,4 +204,4 @@ void Window::move_widget (bool shaded, Widget * widget, int x, int y)
{
GtkWidget * fixed = shaded ? m_shaded : m_normal;
gtk_fixed_move ((GtkFixed *) fixed, widget->gtk (), x * config.scale, y * config.scale);
}
}
9 changes: 8 additions & 1 deletion src/skins/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class Window : public Widget
void set_shapes (GdkRegion * shape, GdkRegion * sshape);
#endif
bool is_shaded () { return m_is_shaded; }
bool has_focus () { return m_is_focused;}
void focus_refresh();
void focus_set (bool focus) {m_is_focused=focus;}
void set_shaded (bool shaded);
void put_widget (bool shaded, Widget * widget, int x, int y);
void move_widget (bool shaded, Widget * widget, int x, int y);
Expand All @@ -66,13 +69,15 @@ class Window : public Widget
bool button_release (GdkEventButton * event);
bool motion (GdkEventMotion * event);
bool close ();

bool m_is_drawn_focused = false;
private:
void apply_shape ();

long focus_hook_id1, focus_hook_id2;
const int m_id;
bool m_is_shaded = false;
bool m_is_moving = false;
bool m_is_focused = false;
GtkWidget * m_normal = nullptr, * m_shaded = nullptr;
#ifdef USE_GTK3
SmartPtr<cairo_region_t, cairo_region_destroy> m_shape, m_sshape;
Expand All @@ -87,5 +92,7 @@ void dock_set_size (int id, int w, int h);
void dock_move_start (int id, int x, int y);
void dock_move (int x, int y);
void dock_change_scale (int old_scale, int new_scale);
bool dock_is_focused ();
void refresh_dock_focus();

#endif