Skip to content

Commit

Permalink
store _window as soon as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ederag committed Feb 26, 2020
1 parent ff1ab0e commit 8f295d6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/hamster/lib/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,8 @@ def __init__(self, interactive = True, framerate = 60,

self.__last_mouse_move = None

self.connect("realize", self.__on_realize)

if interactive:
self.set_can_focus(True)
self.set_events(gdk.EventMask.POINTER_MOTION_MASK
Expand Down Expand Up @@ -1983,7 +1985,6 @@ def do_draw(self, context):
context.scale(aspect_x, aspect_y)

if self.fps is None:
self._window = self.get_window()
self.emit("on-first-frame", context)

cursor, self.mouse_x, self.mouse_y, mods = self._window.get_pointer()
Expand Down Expand Up @@ -2241,6 +2242,10 @@ def __on_button_release(self, scene, event):
self.__check_mouse(event.x, event.y)
return True

def __on_realize(self, widget):
# Store as soon as available. Maybe for performance reasons,
# to avoid get_window() calls in __on_mouse_move ?
self._window = self.get_window()

def __on_scroll(self, scene, event):
target = self.get_sprite_at_position(event.x, event.y)
Expand Down

0 comments on commit 8f295d6

Please sign in to comment.