2009-05-10
Quite a while ago, I began playing with the clutter library as a way to move and display graphics on a fullscreen application interface. With the 0.8 release of the clutter library, the fullscreen function didn't seem to work properly anymore and I was rather perturbed. Instead of taking up the entire screen, a "fullscreened" app would behave as though one had maximized a window. However, earlier today I revisited some python code that uses pyclutter to access the clutter library and I came up with a hack that will solve the fullscreen problem and actually redefines the problem in my eyes.
First, let me show some code that does not work as expected:
After trying different various possible fixes, it appeared that the bug is actually
"the stage fullscreen function behaves like maximize if used before the clutter main loop".
What does that mean? It means that the fullscreen function will work if the function is called after the clutter main() function. But how does one call a function after a mainloop has been initialized? I'm glad you asked.
Check out this code with the fix in place:
Since the clutter library uses Gobject objects as base classes for most clutter classes, including the mainloop, one can use gobject.timeout_add() to call a function after a set amount of time. In the fixed code, a function that calls fullscreen was set to run a few milliseconds after the clutter.main() was called.
Now I need to port the code to Vala and make sure the fix works with the Vala Clutter bindings as well.
First, let me show some code that does not work as expected:
#!/usr/bin/env python import clutter class test: def __init__(self): #create a stage self.stage = clutter.Stage() #set the stage to be fullscreen self.stage.fullscreen() #show the screen self.stage.show_all() #get the key presses self.stage.connect('key-press-event', self.quit) #start the clutter main loop clutter.main() def quit(self,object,event): #quit the main loop clutter.main_quit() if __name__=="__main__": #make an instance of the test t = test()
After trying different various possible fixes, it appeared that the bug is actually
"the stage fullscreen function behaves like maximize if used before the clutter main loop".
What does that mean? It means that the fullscreen function will work if the function is called after the clutter main() function. But how does one call a function after a mainloop has been initialized? I'm glad you asked.
Check out this code with the fix in place:
#!/usr/bin/env python import clutter import gobject class test: def __init__(self): #create a stage self.stage = clutter.Stage() #show the screen self.stage.show_all() #get the key presses self.stage.connect('key-press-event', self.quit) #add a fullscreen function to the gobject timeout gobject.timeout_add(10,self.go_fullscreen) #start the clutter main loop clutter.main() def go_fullscreen(self): self.stage.fullscreen() def quit(self,object,event): #quit the main loop clutter.main_quit() if __name__=="__main__": #make an instance of the test t = test()
Since the clutter library uses Gobject objects as base classes for most clutter classes, including the mainloop, one can use gobject.timeout_add() to call a function after a set amount of time. In the fixed code, a function that calls fullscreen was set to run a few milliseconds after the clutter.main() was called.
Now I need to port the code to Vala and make sure the fix works with the Vala Clutter bindings as well.
Comments