[Spice-devel] [spice-gtk v6 5/9] spicy: keep status of mouse/agent on server mode
Victor Toso
lists at victortoso.com
Thu Feb 9 06:37:57 UTC 2017
Hi,
On Wed, Feb 08, 2017 at 11:41:55AM -0600, Jonathon Jongsma wrote:
> On Tue, 2017-01-31 at 12:08 +0100, Victor Toso wrote:
> > From: Victor Toso <me at victortoso.com>
> >
> > ---
> > tools/spicy.c | 19 ++++++++++++-------
> > 1 file changed, 12 insertions(+), 7 deletions(-)
> >
> > diff --git a/tools/spicy.c b/tools/spicy.c
> > index bffbef8..4712db6 100644
> > --- a/tools/spicy.c
> > +++ b/tools/spicy.c
> > @@ -180,25 +180,30 @@ static int ask_user(GtkWidget *parent, char
> > *title, char *message,
> > return retval;
> > }
> >
> > +#define SPICY_STATUS_LABEL "mouse: %6s, agent: %3s"
> > +#define SPICY_UNGRAB_INFO "Use %s to ungrab mouse"
> > +
> > static void update_status_window(SpiceWindow *win)
> > {
> > - gchar *status;
> > + GString *status;
> >
> > if (win == NULL)
> > return;
> >
> > + status = g_string_new(NULL);
> > + g_string_printf(status, SPICY_STATUS_LABEL,
> > + win->conn->mouse_state,
> > + win->conn->agent_state);
> > +
> > if (win->mouse_grabbed) {
> > SpiceGrabSequence *sequence =
> > spice_display_get_grab_keys(SPICE_DISPLAY(win->spice));
> > gchar *seq = spice_grab_sequence_as_string(sequence);
> > - status = g_strdup_printf("Use %s to ungrab mouse.", seq);
> > + g_string_append_printf(status, "\t"SPICY_UNGRAB_INFO, seq);
> > g_free(seq);
> > - } else {
> > - status = g_strdup_printf("mouse: %s, agent: %s",
> > - win->conn->mouse_state, win->conn->agent_state);
> > }
> >
> > - gtk_label_set_text(GTK_LABEL(win->status), status);
> > - g_free(status);
> > + gtk_label_set_text(GTK_LABEL(win->status), status->str);
> > + g_string_free(status, TRUE);
> > }
> >
> > static void update_status(struct spice_connection *conn)
>
>
> Perhaps I'm missing something, but these #defines only seem to be used
> a single time. What's the benefit of defining them rather than just
> using the literal string as the format argument?
The only reason for using a #define is to tag an label to the string,
which also defines a purpose, in this case 'status label'.
I tend to do that when string is always visible or for a common subset
of messages.
> I generally find that #defines used as format strings are more
> confusing because you can't immediately see how many additional
> arguments need to be passed to the printf function.
That's true. I don't see huge benefit to have this define here so I'll
drop it (also due the fact that no other part of the code does that, so
this would be inconsistent).
Cheers,
toso
>
> Jonathon
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170209/44651be3/attachment.sig>
More information about the Spice-devel
mailing list