Re: can_change_screen property for GtkWindow

Tim Janik <timj gtk org> writes:

> On Tue, 1 Oct 2002, Owen Taylor wrote:
> > 
> > [ Continuing the "simple bug turns into thousand line patch" saga... ]
> > 
> > It appears that we need a way to know whether or not it is 
> > safe for GTK+ to move a widget between screens.
> > 
> > Use cases for this:
> > 
> >  A) For drag-and-drop, GTK+ needs to know whether the icon set using
> >     gtk_drag_set_icon_window() can be used across multiple screens.
> > 
> >  B) We eventually want the ability for window managers to migrate
> >     windows across screens, and for users to migrate applications
> >     between different displays. GTK+ needs a way to know whether it
> >     should advertise support for such capabilities.
> > 
> > The attached patch adds the GtkWindow API:
> > 
> >  void     gtk_window_set_can_change_screen         (GtkWindow *window,
> > 						   gboolean   can_change_screen);
> >  void     gtk_window_unset_can_change_screen       (GtkWindow *window);
> >  gboolean gtk_window_get_can_change_screen         (GtkWindow *window);
> >  void     gtk_window_set_default_can_change_screen (gboolean   can_change_screen);
> >  gboolean gtk_window_get_default_can_change_screen (GtkWindow *window);
> these API names frighten me, wouldn't screen_changable be better?

I would never be able to remember whether it was changeable
or changable for one thing... plus you can't take "able" onto
phrases onto English and have it sound at all natural.
It just doesn't really work, so I had to fall back to
the can_blah wording.

(We do have some precendent for can_ properties, - can_focus,
can_default, though we admitably have more "able" properties)
> > And properties "can_change_screen" and "can_change_screen_set".
> why would you have to know whether the user set the property at all
> (i.e. need can_change_screen_set)? if that's an important scenario
> different from "user allowed screen changes" and "user forbid screen
> changes", then the cleaner aproach is a tri-state property, i.e.
> an enumeration. and btw, i assume that you mean:
> gtk_window_set_default_can_change_screen (FALSE);
> /* window->can_change_screen_set = FALSE; */
> prop1 = gtk_window_get_can_change_screen (window);
> gtk_window_set_default_can_change_screen (TRUE);
> prop2 = gtk_window_get_can_change_screen (window);
> to return different values for prop1 and prop2. still, property
> change notification for ::can_change_screen will have to be
> queued on window in gtk_window_set_default_can_change_screen (TRUE);
OK, this is a dinky API, so probably not worth a lot of discussion,
but I'll go into some detail:


A) A way of setting a window to one of three states
    "can change screen", "cannot change screen", "use default

B) A way of getting the value set in A).

C) A way to get the effective value of "can change screen"
   property taking into account the default value.

D) Exposure of A/B through the property system (with monitoring)
   so it can be set in a GUI builder.

Similar API:

The direction for GtkWidget:

 typedef enum
 } GtkTextDirection;

 void             gtk_widget_set_direction         (GtkWidget        *widget,
						   GtkTextDirection  dir);
 GtkTextDirection gtk_widget_get_direction         (GtkWidget        *widget);
 [ Gets the _effective direction_ - not the value set by set_direction() ]
 void             gtk_widget_set_default_direction (GtkTextDirection  dir);
 GtkTextDirection gtk_widget_get_default_direction (void);

 ::direction_changed (GtkWidget        *widget,
		      GtkTextDirection  previous_direction);

 [ Signal is notification on _effective_ direction, not on the direction set
   by set_direction() ]

Style properties on GtkTextTag/GtkCellRenderer:

 For example

  GtkTextTag::strikethrough / GtkTextTag::strikethrough_set

 Behavior here is that setting GtkTextTag::strikethrough turns
 on GtkTextTag::strikethrough_set, getting GtkTextTag::strikethrough
 always returns the value set for GtkTextTag::strikethrough, 
 not the effective value. 

 (The effective value here isn't even well defined, since a tag
 can be used in many contexts)

Train of thought:

 * Adding a tristate enum here is just annoying. It makes sense
   for GtkTextDirection because neither LTR or RTL is clearly
   "TRUE", but here it's: 


   Or something instead of the obvious boolean value.

 * The "foo" "foo_set" convention for properties is already 
   well established, and it's easy for GUI builders to
   make reasonable GUI's for it.

   So, it made sense to me to have:

   Properties as the property interface. get/notify
   can_change_screen() could reasonably either be:

    - value set
    - effective value
   I decided to go with the value set because:

    - I don't know any particular reason to monitor the
      effective value (when this window becomes possible to
      move between screens, I'll move it?)
    - notifying the effective value is somewhat code-bloaty
      and expensive.

 * For the C API, a minimum convenient interface is

   void     gtk_window_set_can_change_screen         (GtkWindow *window,
						      gboolean   can_change_screen);
   gboolean gtk_window_get_can_change_screen         (GtkWindow *window); /* effective value */
   gboolean gtk_window_get_default_can_change_screen (void);
   void     gtk_window_set_default_can_change_screen (gboolean   can_change_screen);

  I added:

   void     gtk_window_unset_can_change_screen       (GtkWindow *window);

  because I dislike having actions (set_can_change_screen()) that can't
  be undone.

Are there other possible interfaces? Yes, e.g., with a special enum:

  typedef enum {
  } GtkScreenChangeMode;

   void                gtk_window_set_screen_change_mode (GtkWindow           *window,
                                                          GtkScreenChangeMode  mode);
   GtkScreenChangeMode gtk_window_get_screen_change_mode (GtkWindow           *window);
   gboolean            gtk_window_can_change_screen      (GtkWindow           *window);

   void                gtk_window_set_default_screen_change_mode  (GtkScreenChangeMode mode);
   GtkScreenChangeMode gtk_window_get_default_screen_change_mode  (void);

  And a ::screen_change_mode property.

But think my API works fine and is less clunky.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]