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

Fixed-size notes support #641

Open
wants to merge 1 commit into
base: master
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
5 changes: 5 additions & 0 deletions stickynotes/org.mate.stickynotes.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@
<summary>Whether to ask for confirmation when deleting a note</summary>
<description>Empty notes are always deleted without confirmation.</description>
</key>
<key name="fixed-size" type="b">
<default>false</default>
<summary>Whether to prevent note resizing on all notes</summary>
<description>If this option is enabled, resizing is restricted on all notes.</description>
</key>
</schema>
</schemalist>
17 changes: 17 additions & 0 deletions stickynotes/sticky-notes-preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,23 @@
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="fixed_size_check">
<property name="label" translatable="yes">Force fixed size notes</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Choose whether to restrict notes resizing</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="width">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand Down
44 changes: 43 additions & 1 deletion stickynotes/stickynotes.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void
buffer_changed (GtkTextBuffer *buffer,
StickyNote *note)
{
if ( (note->h + note->y) > stickynotes->max_height )
if ( (note->h + note->y) > stickynotes->max_height && (!note->force_fixed_size) )
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (note->w_scroller),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

Expand Down Expand Up @@ -251,6 +251,8 @@ stickynote_new_aux (GdkScreen *screen,
stickynote_set_font (note, NULL, TRUE);
stickynote_set_locked (note, FALSE);

stickynote_set_fixed_size(note, stickynotes->force_fixed_size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces and unify the code format


gtk_widget_realize (note->w_window);

/* Connect a popup menu to all buttons and title */
Expand Down Expand Up @@ -750,6 +752,46 @@ stickynote_set_visible (StickyNote *note,
}
}

/* Set forced fixed size */
void stickynote_set_fixed_size (StickyNote *note,
gboolean force_fixed_size)
{
note->force_fixed_size = force_fixed_size;

if (force_fixed_size) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem with the judgment here

gint w, h;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (note->w_scroller),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (note->w_body),
GTK_WRAP_CHAR);
gtk_widget_set_visible (note->w_resize_se, FALSE);
gtk_widget_set_visible (note->w_resize_sw, FALSE);
if (note->w == 0 || note->h == 0) {
w = g_settings_get_int (stickynotes->settings, "default-width");
h = g_settings_get_int (stickynotes->settings, "default-height");
}
else {
w = note->w;
h = note->h;
}
gtk_window_set_default_size (GTK_WINDOW (note->w_window), w, h);
gtk_window_resize (GTK_WINDOW (note->w_window), w, h);
gtk_window_set_resizable(GTK_WINDOW (note->w_window), FALSE);
}
else {
GtkScrollablePolicy vscroll_pol = GTK_POLICY_NEVER;
if ( (note->h + note->y) > stickynotes->max_height )
vscroll_pol = GTK_POLICY_AUTOMATIC;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (note->w_scroller),
GTK_POLICY_NEVER, vscroll_pol);
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (note->w_body),
GTK_WRAP_WORD);
gtk_widget_set_visible (note->w_resize_se, TRUE);
gtk_widget_set_visible (note->w_resize_sw, TRUE);
gtk_window_set_resizable(GTK_WINDOW (note->w_window), TRUE);
}
}

/* Add a sticky note */
void
stickynotes_add (GdkScreen *screen)
Expand Down
3 changes: 3 additions & 0 deletions stickynotes/stickynotes.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ typedef struct
gchar *font_color; /* Font color */
gchar *font; /* Note font */
gboolean locked; /* Note locked state */
gboolean force_fixed_size; /* Note resizing is restricted */

gint x; /* Note x-coordinate */
gint y; /* Note y-coordinate */
Expand Down Expand Up @@ -91,6 +92,8 @@ void stickynote_set_locked (StickyNote *note,
gboolean locked);
void stickynote_set_visible (StickyNote *note,
gboolean visible);
void stickynote_set_fixed_size (StickyNote *note,
gboolean force_fixed_size);

void stickynote_change_properties (StickyNote *note);

Expand Down
14 changes: 13 additions & 1 deletion stickynotes/stickynotes_applet.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ stickynotes_applet_init_prefs (void)
stickynotes->w_prefs_desktop =
GTK_WIDGET (&GTK_CHECK_BUTTON (gtk_builder_get_object (stickynotes->builder,
"desktop_hide_check"))->toggle_button);
stickynotes->w_prefs_fixed_size =
GTK_WIDGET (&GTK_CHECK_BUTTON (gtk_builder_get_object (stickynotes->builder,
"fixed_size_check"))->toggle_button);

g_signal_connect (stickynotes->w_prefs, "response",
G_CALLBACK (preferences_response_cb), NULL);
Expand All @@ -287,6 +290,8 @@ stickynotes_applet_init_prefs (void)
G_CALLBACK (preferences_save_cb), NULL);
g_signal_connect_swapped (stickynotes->w_prefs_desktop, "toggled",
G_CALLBACK (preferences_save_cb), NULL);
g_signal_connect_swapped (stickynotes->w_prefs_fixed_size, "toggled",
G_CALLBACK (preferences_save_cb), NULL);

{
GtkSizeGroup *group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
Expand Down Expand Up @@ -346,6 +351,8 @@ stickynotes_applet_init_prefs (void)
gtk_widget_set_sensitive (stickynotes->w_prefs_sticky, FALSE);
if (!g_settings_is_writable (stickynotes->settings, "force-default"))
gtk_widget_set_sensitive (stickynotes->w_prefs_force, FALSE);
if (!g_settings_is_writable (stickynotes->settings, "fixed-size"))
gtk_widget_set_sensitive (stickynotes->w_prefs_fixed_size, FALSE);

stickynotes_applet_update_prefs ();
}
Expand Down Expand Up @@ -468,7 +475,7 @@ void
stickynotes_applet_update_prefs (void)
{
gint width, height;
gboolean sys_color, sys_font, sticky, force_default, desktop_hide;
gboolean sys_color, sys_font, sticky, force_default, desktop_hide, fixed_size;
char *font_str;
char *color_str, *font_color_str;
GdkRGBA color, font_color;
Expand All @@ -490,6 +497,8 @@ stickynotes_applet_update_prefs (void)
"force-default");
desktop_hide = g_settings_get_boolean (stickynotes->settings,
"desktop-hide");
fixed_size = g_settings_get_boolean (stickynotes->settings,
"fixed-size");

font_str = g_settings_get_string (stickynotes->settings,
"default-font");
Expand Down Expand Up @@ -524,6 +533,9 @@ stickynotes_applet_update_prefs (void)
force_default);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (stickynotes->w_prefs_desktop),
desktop_hide);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (stickynotes->w_prefs_fixed_size),
fixed_size);
stickynotes->force_fixed_size = fixed_size;

gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (stickynotes->w_prefs_color),
&color);
Expand Down
2 changes: 2 additions & 0 deletions stickynotes/stickynotes_applet.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef struct
GtkWidget *w_prefs_sticky;
GtkWidget *w_prefs_force;
GtkWidget *w_prefs_desktop;
GtkWidget *w_prefs_fixed_size;

GList *notes; /* Linked-List of all the sticky notes */
GList *applets; /* Linked-List of all the applets */
Expand All @@ -63,6 +64,7 @@ typedef struct
guint last_timeout_data;

gboolean visible; /* Toggle show/hide notes */
gboolean force_fixed_size; /* Force fixed size notes */
} StickyNotes;

/* Sticky Notes Applet */
Expand Down
14 changes: 14 additions & 0 deletions stickynotes/stickynotes_applet_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ preferences_save_cb (gpointer data)
gboolean sticky;
gboolean force_default;
gboolean desktop_hide;
gboolean fixed_size;
gdouble adjustment_value;

adjustment_value = gtk_adjustment_get_value (stickynotes->w_prefs_width);
Expand All @@ -464,6 +465,7 @@ preferences_save_cb (gpointer data)
sticky = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (stickynotes->w_prefs_sticky));
force_default = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (stickynotes->w_prefs_force));
desktop_hide = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (stickynotes->w_prefs_desktop));
fixed_size = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (stickynotes->w_prefs_fixed_size));

if (g_settings_is_writable (stickynotes->settings,
"default-width"))
Expand Down Expand Up @@ -493,6 +495,10 @@ preferences_save_cb (gpointer data)
"desktop-hide"))
g_settings_set_boolean (stickynotes->settings,
"desktop-hide", desktop_hide);
if (g_settings_is_writable (stickynotes->settings,
"fixed-size"))
g_settings_set_boolean (stickynotes->settings,
"fixed-size", fixed_size);
}

/* Preferences Callback : Change color. */
Expand Down Expand Up @@ -599,6 +605,14 @@ preferences_apply_cb (GSettings *settings,
}
}

else if (!strcmp (key, "fixed-size")) {
for (l = stickynotes->notes; l; l = l->next) {
note = l->data;
stickynote_set_fixed_size (note,
stickynotes->force_fixed_size);
}
}

stickynotes_applet_update_prefs ();
stickynotes_applet_update_menus ();
}
Expand Down
3 changes: 3 additions & 0 deletions stickynotes/stickynotes_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ gboolean stickynote_resize_cb (GtkWidget *widget,
GdkEventButton *event,
StickyNote *note)
{
if (note->force_fixed_size)
return FALSE;

if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
if (widget == note->w_resize_se)
gtk_window_begin_resize_drag (GTK_WINDOW (note->w_window),
Expand Down