[Sugar-devel] Fwd: Making activities close from the sugar frame

Tomeu Vizoso tomeu at sugarlabs.org
Wed Mar 4 05:41:50 EST 2009


Btw, at least in Sugar 0.84, this is already fixed. I can start from
terminal a normal X app and clicking on the Close option in the
palette will close it properly (should be the equivalent to clicking
the X button in most window decorations).

HTH,

Tomeu

On Fri, Feb 27, 2009 at 11:45, Bert Freudenberg <bert at freudenbergs.de> wrote:
> If generalized this is perhaps not so bad an idea for sugarizing
> regular X apps. The bundle's activity.info could declare a regexp to
> match the WM_NAME of a window and Sugar then could associate that
> activity with the window (associating a window with an activity
> instance is the whole purpose of the SUUGAR_* WM properties). As long
> as this also restricts the number of simultaneously running instances
> to 1 it should work (because you could not distinguish two different
> instances).
>
> This would make the libsugarize hack unnecessary. I like it already :)
>
> - Bert -
>
> On 27.02.2009, at 10:07, Bibek Kafle wrote:
>
>> Hi,
>>
>> The problem we talked about is mostly fixed now. John Maloney said
>> that Scratch is going to handle being closed from the frame from the
>> next release. Opening firefox opened two icons on the frame: the
>> firefox icon and another black circle. There was a bug filed
>> somewhere that said that that was because some X properties were not
>> set before the window opened. There was something about how to solve
>> this from the activity itself, but I couldn't understand most of it
>> so I added the following fucntion to /usr/share/sugar/shell/model/
>> homemodel.py and then called it from HomeModel._window_opened_cb()
>> (eg. _fix_icons('org.laptop.FirefoxActivity', 'Mozilla Firefox',
>> self._activities, window) doing this made the black little circle go
>> away, and now closing the firefox icon from the frame works. But I'm
>> not sure if this is the best solution.
>>
>> Thanks
>> Bibek
>>
>> def _fix_icons(reg_exp, wm_name, activities, wnck_window):
>>     # reg_exp is the regular expression to match the service name
>>     # wm_name is the value of the WM_NAME property of the X window
>>     # activities is the collection of the HomeActivity instances
>>     # wnck_window is the new X window
>>
>>     window = gtk.gdk.window_foreign_new(wnck_window.get_xid())
>>
>>     # Check if the new window is window with wm_name
>>     if window.property_get('WM_NAME' , 'STRING')[2] == wm_name:
>>
>>         for i in activities:
>>
>>             # find the HomeActivity instance with service name
>> matching reg_exp
>>
>>             if i.get_window() is not None:
>>
>>                 if re.match(reg_exp, str(i.get_type())) != None:
>>
>>                     if str(_get_sugar_window_type(i.get_window()))
>> == 'launcher':
>>
>>                        # Set sugar specific X properties
>>
>>                         window.property_change('_SUGAR_BUNDLE_ID',
>> 'STRING', 8, gtk.gdk.PROPERTY_NEW_VALUE, str(i.get_type))
>>                         window.property_change('_SUGAR_ACTIVITY_ID',
>> 'STRING', 8, gtk.gdk.PROPERTY_NEW_VALUE, str(i.get_activity_id()))
>>                         window.property_change('_NET_WM_NAME',
>> 'STRING', 8, gtk.gdk.PROPERTY_NEW_VALUE, str(i.get_title))
>>                         window.property_change('_NET_WM_PID',
>> 'STRING', 8, gtk.gdk.PROPERTY_NEW_VALUE, str(i.get_pid))
>>                         window.property_change('_SUGAR_WINDOW_TYPE',
>> 'STRING', 8, gtk.gdk.PROPERTY_NEW_VALUE, 'Firefox')
>>
>>
>>
>>
>>
>> ---------- Forwarded message ----------
>> From: Bernie Innocenti <bernie at codewiz.org>
>> Date: Wed, Feb 25, 2009 at 3:33 AM
>> Subject: Re: Making activities close from the sugar frame
>> To: Bibek Kafle <bibek.kafle at olenepal.org>
>>
>>
>> Any particular reason why this is off-list?  Can we forward it to
>> sugar-devel@ so the other developers can see what we're up to?
>>
>> Bibek Kafle wrote:
>> > Hi,
>> > To make firefox and scratch close from the sugar frame I tried to
>> change
>> > a method in the CurrentActivityPallete class in
>> > /usr/sugar/sugar/shell/view/palletes.py to send SIGKILL signal to
>> the
>> > activity after getting the pid from the HomeActivity object, but it
>> > didn't work. The shell log said that the operation was not
>> permitted.
>>
>> It's Rainbow's fault!  Activities run with a different UID for
>> isolation.
>>
>>
>> > Then I tried to use a c wrapper to make to set setuid for a python
>> > script that killed the pid, but it still said that the operation
>> was not
>> > permitted. Even if that worked, Bryan says that simply killing the
>> > process will be dirty because firefox will say that the previous
>> session
>> > was closed unexpectedly the next time it is run. I'm out of ideas
>> now!
>>
>> Indeed, this is not how gnome and kde close applications.
>>
>> > Bryan said that you had an idea about how I can go about making
>> scratch
>> > and firefox close from the sugar frame. He said something about
>> making a
>> > wrapper that handles X11 close events. How do I do that?
>> > Bibek
>>
>> If you find the XID for the window somwewhere in the activity info
>> managed by Sugar, you can send it a window close event.
>>
>> I'm not sure about the details, but:
>>
>>  - see  "man XSendEvent"
>>
>>  - it seems you have to send an event called ClientMessage
>>   http://tronche.com/gui/x/xlib/events/client-communication/client-message.html
>>
>>  - The ancient ICCCM specification tells what needs to be done
>>   http://tronche.com/gui/x/icccm/sec-4.html#s-4.2.8.1
>>
>> I would just grab some example code (for example a window manager)
>> instead
>> of reading through the specs
>>
>> --
>>   // Bernie Innocenti - http://www.codewiz.org/
>>  \X/  Sugar Labs       - http://www.sugarlabs.org/
>>
>> _______________________________________________
>> Sugar-devel mailing list
>> Sugar-devel at lists.sugarlabs.org
>> http://lists.sugarlabs.org/listinfo/sugar-devel
>
>
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>


More information about the Sugar-devel mailing list