Commit 1eee87d2 authored by Christian Persch's avatar Christian Persch

widget: Move GtkSettings change handling to Widget

parent 69dfd0c3
...@@ -8284,31 +8284,11 @@ Terminal::widget_unrealize() ...@@ -8284,31 +8284,11 @@ Terminal::widget_unrealize()
m_modifiers = 0; m_modifiers = 0;
} }
static void
vte_terminal_settings_notify_cb (GtkSettings *settings,
GParamSpec *pspec,
vte::terminal::Terminal* that)
{
that->widget_settings_notify();
}
void void
Terminal::widget_settings_notify() Terminal::set_blink_settings(bool blink,
int blink_time,
int blink_timeout) noexcept
{ {
gboolean blink;
int blink_time = 1000;
int blink_timeout = G_MAXINT;
g_object_get(gtk_widget_get_settings(m_widget),
"gtk-cursor-blink", &blink,
"gtk-cursor-blink-time", &blink_time,
"gtk-cursor-blink-timeout", &blink_timeout,
nullptr);
_vte_debug_print(VTE_DEBUG_MISC,
"Cursor blinking settings: blink=%d time=%d timeout=%d\n",
blink, blink_time, blink_timeout);
m_cursor_blink_cycle = blink_time / 2; m_cursor_blink_cycle = blink_time / 2;
m_cursor_blink_timeout = blink_timeout; m_cursor_blink_timeout = blink_timeout;
...@@ -8325,34 +8305,6 @@ Terminal::widget_settings_notify() ...@@ -8325,34 +8305,6 @@ Terminal::widget_settings_notify()
} }
} }
void
Terminal::widget_screen_changed (GdkScreen *previous_screen)
{
GtkSettings *settings;
auto gdk_screen = gtk_widget_get_screen (m_widget);
if (previous_screen != NULL &&
(gdk_screen != previous_screen || gdk_screen == NULL)) {
settings = gtk_settings_get_for_screen (previous_screen);
g_signal_handlers_disconnect_matched (settings, G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL,
this);
}
if (gdk_screen == previous_screen || gdk_screen == nullptr)
return;
widget_settings_notify();
settings = gtk_widget_get_settings(m_widget);
g_signal_connect (settings, "notify::gtk-cursor-blink",
G_CALLBACK (vte_terminal_settings_notify_cb), this);
g_signal_connect (settings, "notify::gtk-cursor-blink-time",
G_CALLBACK (vte_terminal_settings_notify_cb), this);
g_signal_connect (settings, "notify::gtk-cursor-blink-timeout",
G_CALLBACK (vte_terminal_settings_notify_cb), this);
}
Terminal::~Terminal() Terminal::~Terminal()
{ {
struct vte_match_regex *regex; struct vte_match_regex *regex;
......
...@@ -768,14 +768,15 @@ public: ...@@ -768,14 +768,15 @@ public:
void widget_scroll(GdkEventScroll *event); void widget_scroll(GdkEventScroll *event);
bool widget_motion_notify(GdkEventMotion *event); bool widget_motion_notify(GdkEventMotion *event);
void widget_draw(cairo_t *cr); void widget_draw(cairo_t *cr);
void widget_screen_changed (GdkScreen *previous_screen);
void widget_get_preferred_width(int *minimum_width, void widget_get_preferred_width(int *minimum_width,
int *natural_width); int *natural_width);
void widget_get_preferred_height(int *minimum_height, void widget_get_preferred_height(int *minimum_height,
int *natural_height); int *natural_height);
void widget_size_allocate(GtkAllocation *allocation); void widget_size_allocate(GtkAllocation *allocation);
void widget_settings_notify(); void set_blink_settings(bool blink,
int blink_time,
int blink_timeout) noexcept;
void expand_rectangle(cairo_rectangle_int_t& rect) const; void expand_rectangle(cairo_rectangle_int_t& rect) const;
void paint_area(GdkRectangle const* area); void paint_area(GdkRectangle const* area);
......
...@@ -82,6 +82,14 @@ im_delete_surrounding_cb(GtkIMContext* im_context, ...@@ -82,6 +82,14 @@ im_delete_surrounding_cb(GtkIMContext* im_context,
return that->terminal()->im_delete_surrounding(offset, n_chars); return that->terminal()->im_delete_surrounding(offset, n_chars);
} }
static void
settings_notify_cb(GtkSettings* settings,
GParamSpec* pspec,
vte::platform::Widget* that)
{
that->settings_changed();
}
Widget::Widget(VteTerminal* t) noexcept : Widget::Widget(VteTerminal* t) noexcept :
m_widget{&t->widget} m_widget{&t->widget}
{ {
...@@ -222,6 +230,52 @@ Widget::realize() noexcept ...@@ -222,6 +230,52 @@ Widget::realize() noexcept
m_terminal->widget_realize(); m_terminal->widget_realize();
} }
void
Widget::screen_changed(GdkScreen *previous_screen) noexcept
{
auto gdk_screen = gtk_widget_get_screen(m_widget);
if (previous_screen != nullptr &&
(gdk_screen != previous_screen || gdk_screen == nullptr)) {
auto settings = gtk_settings_get_for_screen(previous_screen);
g_signal_handlers_disconnect_matched(settings, G_SIGNAL_MATCH_DATA,
0, 0, nullptr, nullptr,
this);
}
if (gdk_screen == previous_screen || gdk_screen == nullptr)
return;
settings_changed();
auto settings = gtk_widget_get_settings(m_widget);
g_signal_connect (settings, "notify::gtk-cursor-blink",
G_CALLBACK(settings_notify_cb), this);
g_signal_connect (settings, "notify::gtk-cursor-blink-time",
G_CALLBACK(settings_notify_cb), this);
g_signal_connect (settings, "notify::gtk-cursor-blink-timeout",
G_CALLBACK(settings_notify_cb), this);
}
void
Widget::settings_changed() noexcept
{
gboolean blink;
int blink_time;
int blink_timeout;
g_object_get(gtk_widget_get_settings(m_widget),
"gtk-cursor-blink", &blink,
"gtk-cursor-blink-time", &blink_time,
"gtk-cursor-blink-timeout", &blink_timeout,
nullptr);
_vte_debug_print(VTE_DEBUG_MISC,
"Cursor blinking settings: blink=%d time=%d timeout=%d\n",
blink, blink_time, blink_timeout);
m_terminal->set_blink_settings(blink, blink_time, blink_timeout);
}
void void
Widget::set_cursor(Cursor type) noexcept Widget::set_cursor(Cursor type) noexcept
{ {
......
...@@ -56,7 +56,6 @@ public: ...@@ -56,7 +56,6 @@ public:
void unmap() noexcept; void unmap() noexcept;
void style_updated() noexcept { m_terminal->widget_style_updated(); } void style_updated() noexcept { m_terminal->widget_style_updated(); }
void draw(cairo_t *cr) noexcept { m_terminal->widget_draw(cr); } void draw(cairo_t *cr) noexcept { m_terminal->widget_draw(cr); }
void screen_changed (GdkScreen *previous_screen) noexcept { m_terminal->widget_screen_changed(previous_screen); }
void get_preferred_width(int *minimum_width, void get_preferred_width(int *minimum_width,
int *natural_width) const noexcept { m_terminal->widget_get_preferred_width(minimum_width, natural_width); } int *natural_width) const noexcept { m_terminal->widget_get_preferred_width(minimum_width, natural_width); }
void get_preferred_height(int *minimum_height, void get_preferred_height(int *minimum_height,
...@@ -83,6 +82,9 @@ public: ...@@ -83,6 +82,9 @@ public:
GtkSelectionData *data, GtkSelectionData *data,
guint info) noexcept { m_terminal->widget_clipboard_requested(target_clipboard, data, info); } guint info) noexcept { m_terminal->widget_clipboard_requested(target_clipboard, data, info); }
void screen_changed (GdkScreen *previous_screen) noexcept;
void settings_changed() noexcept;
void set_hadjustment(GtkAdjustment *adjustment) noexcept { m_terminal->widget_set_hadjustment(adjustment); } void set_hadjustment(GtkAdjustment *adjustment) noexcept { m_terminal->widget_set_hadjustment(adjustment); }
GtkAdjustment* get_hadjustment() const noexcept { return m_terminal->m_hadjustment; } GtkAdjustment* get_hadjustment() const noexcept { return m_terminal->m_hadjustment; }
void set_vadjustment(GtkAdjustment *adjustment) noexcept { m_terminal->widget_set_vadjustment(adjustment); } void set_vadjustment(GtkAdjustment *adjustment) noexcept { m_terminal->widget_set_vadjustment(adjustment); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment