[virt-tools-list] [PATCH virt-manager] Do not use deprecated gdk_cursor_new

Pavel Grunt pgrunt at redhat.com
Wed May 3 14:50:19 UTC 2017


On Wed, 2017-05-03 at 10:31 -0400, Cole Robinson wrote:
> On 05/03/2017 05:09 AM, Pavel Grunt wrote:
> > It relies on the presence of X cursor fonts in the system. Use
> > recommended gdk_cursor_new_from_name and use cursor names that
> > works
> > on different backends.
> > 
> > Deprecated since Gdk 3.16
> > 
> > https://bugzilla.redhat.com/show_bug.cgi?id=1442612
> > ---
> >  virtManager/asyncjob.py  |  5 +++--
> >  virtManager/baseclass.py | 12 +++++++-----
> >  2 files changed, 10 insertions(+), 7 deletions(-)
> > 
> > diff --git a/virtManager/asyncjob.py b/virtManager/asyncjob.py
> > index 0fd3beed..cbc872c4 100644
> > --- a/virtManager/asyncjob.py
> > +++ b/virtManager/asyncjob.py
> > @@ -286,8 +286,9 @@ class vmmAsyncJob(vmmGObjectUI):
> >              self.topwin.present()
> >  
> >          if not self.cancel_cb and self.show_progress:
> > -            self.topwin.get_window().set_cursor(
> > -                            Gdk.Cursor.new(Gdk.CursorType.WATCH))
> > +            gdk_window = self.topwin.get_window()
> > +            gdk_window.set_cursor(
> > +                Gdk.Cursor.new_from_name(gdk_window.get_display()
> > , "progress"))
> >          self._bg_thread.start()
> >  
> >  
> > diff --git a/virtManager/baseclass.py b/virtManager/baseclass.py
> > index 7f3b7592..73b87fa7 100644
> > --- a/virtManager/baseclass.py
> > +++ b/virtManager/baseclass.py
> > @@ -241,15 +241,17 @@ class vmmGObjectUI(vmmGObject):
> >  
> >      def set_finish_cursor(self):
> >          self.topwin.set_sensitive(False)
> > -        cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH)
> > -        self.topwin.get_window().set_cursor(cursor>
> > +        gdk_window = self.topwin.get_window()
> > +        cursor =
> > Gdk.Cursor.new_from_name(gdk_window.get_display(), "progress")
> > +        gdk_window.set_cursor(cursor)
> >  
> >      def reset_finish_cursor(self, topwin=None):
> >          if not topwin:
> >              topwin = self.topwin
> >  
> >          topwin.set_sensitive(True)
> > -        if not topwin.get_window():
> > +        gdk_window = topwin.get_window()
> > +        if not gdk_window:
> >              return
> > -        cursor = Gdk.Cursor.new(Gdk.CursorType.TOP_LEFT_ARROW)
> > -        topwin.get_window().set_cursor(cursor)
> > +        cursor =
> > Gdk.Cursor.new_from_name(gdk_window.get_display(), "default")
> > +        gdk_window.set_cursor(cursor)
> > 
> 
> 
> Does using Gdk.Cursor.new_from_display() fix the issue as well? 

no, the same issue. If the cursor id is not available than it will
crash

> That way we
> can still use the CursorType value, rather than hardcoded strings
what is the benefit of using hardcoded cursor types instead of strings
which are defined in all the platforms :)?

https://developer.gnome.org/gdk3/stable/gdk3-Cursors.html#GdkCursorTyp
e


> 
> Also is there an easy way to reproduce that bug? 
remove/rename the cursor - the theme is stored in /usr/share/icons/

> I couldn't hit it with stock
> config
> 
I think the real bug is in the gdk bindings - per docs it is allowed
to return NULL from the constructor if the cursor type/name does not
exist - "Returns a new GdkCursor, or NULL if there is no cursor with
the given name. "

https://developer.gnome.org/gdk3/stable/gdk3-Cursors.html#gdk-cursor-n
ew-from-name

Anyway I think it is better to try-catch than forcing users to switch
their cursor theme :)

Thanks,
Pavel

> Thanks,
> Cole




More information about the virt-tools-list mailing list