~ubuntu-branches/ubuntu/precise/xfwm4/precise-updates

« back to all changes in this revision

Viewing changes to src/terminate.c

  • Committer: Bazaar Package Importer
  • Author(s): Jérôme Guelfucci, Jérôme Guelfucci, Lionel Le Folgoc
  • Date: 2009-01-30 18:28:59 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20090130182859-1tci3n1f1hhppvc2
Tags: 4.5.99.1-0ubuntu1
[ Jérôme Guelfucci ]
* Merge with Debian Xfce UNRELEASED, remaining Ubuntu changes:
  - debian/xfwm4.1: update bug reporting address (LP instead of Debian BTS).

[ Lionel Le Folgoc ]
* debian/control: use our Vcs-* fields.
* Bugs fixed by this new release:
  - "User interface of focused application is covered by another application's
    new window in Xfce" (LP: #250101)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*      $Id$
 
2
 
 
3
        This program is free software; you can redistribute it and/or modify
 
4
        it under the terms of the GNU General Public License as published by
 
5
        the Free Software Foundation; either version 2, or (at your option)
 
6
        any later version.
 
7
 
 
8
        This program is distributed in the hope that it will be useful,
 
9
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
        GNU General Public License for more details.
 
12
 
 
13
        You should have received a copy of the GNU General Public License
 
14
        along with this program; if not, write to the Free Software
 
15
        Foundation, Inc., Inc., 51 Franklin Street, Fifth Floor, Boston,
 
16
        MA 02110-1301, USA.
 
17
 
 
18
        metacity - (c) 2001, 2002 Havoc Pennington
 
19
        xfwm4    - (c) 2002-2009 Olivier Fourdan
 
20
 
 
21
 */
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
#include "config.h"
 
25
#endif
 
26
 
 
27
#include <sys/types.h>
 
28
#include <signal.h>
 
29
#include <unistd.h>
 
30
#include <errno.h>
 
31
 
 
32
#include "client.h"
 
33
 
 
34
void
 
35
terminateCloseDialog (Client *c)
 
36
{
 
37
    g_return_if_fail (c != NULL);
 
38
 
 
39
    if (c->dialog_pid)
 
40
    {
 
41
        kill (c->dialog_pid, SIGKILL);
 
42
        c->dialog_pid = 0;
 
43
    }
 
44
    if (c->dialog_fd >= 0)
 
45
    {
 
46
        close (c->dialog_fd);
 
47
        c->dialog_fd = -1;
 
48
    }
 
49
}
 
50
 
 
51
static gboolean
 
52
terminateProcessIO (GIOChannel   *channel,
 
53
                    GIOCondition  condition,
 
54
                    gpointer      data)
 
55
{
 
56
    Client *c;
 
57
    char *str;
 
58
    gsize len;
 
59
    GError *err;
 
60
 
 
61
    c = (Client *) data;
 
62
    g_return_val_if_fail (c != NULL, FALSE);
 
63
 
 
64
    str = NULL;
 
65
    len = 0;
 
66
    err = NULL;
 
67
 
 
68
    if (condition & G_IO_IN)
 
69
    {
 
70
        g_io_channel_read_to_end (channel, &str, &len, &err);
 
71
 
 
72
        if (err)
 
73
        {
 
74
            g_warning (_("Error reading data from child process: %s\n"), err->message);
 
75
            g_error_free (err);
 
76
        }
 
77
        if (len > 0)
 
78
        {
 
79
            if (!g_strncasecmp(str, "yes", 3))
 
80
            {
 
81
                clientTerminate (c);
 
82
            }
 
83
        }
 
84
 
 
85
        g_free (str);
 
86
    }
 
87
 
 
88
    terminateCloseDialog (c);
 
89
 
 
90
    return FALSE;
 
91
}
 
92
 
 
93
gboolean
 
94
terminateShowDialog (Client *c)
 
95
{
 
96
    ScreenInfo *screen_info;
 
97
    char *argv[4];
 
98
    GError *err;
 
99
    int child_pid;
 
100
    int outpipe;
 
101
    GIOChannel *channel;
 
102
    gchar *xid;
 
103
 
 
104
    if (c->dialog_pid > 0)
 
105
    {
 
106
        return FALSE;
 
107
    }
 
108
 
 
109
    screen_info = c->screen_info;
 
110
    xid = g_strdup_printf ("0x%lx", c->window);
 
111
 
 
112
    argv[0] = LIBEXECDIR"/xfce4/xfwm4/helper-dialog";
 
113
    argv[1] = xid;
 
114
    argv[2] = c->name;
 
115
    argv[3] = NULL;
 
116
 
 
117
    err = NULL;
 
118
    if (!gdk_spawn_on_screen_with_pipes (screen_info->gscr, NULL, argv, NULL,
 
119
                                 0, NULL, NULL, &child_pid, NULL, &outpipe,
 
120
                                 NULL, &err))
 
121
    {
 
122
        g_warning (_("Cannot spawn helper-dialog: %s\n"), err->message);
 
123
        g_error_free (err);
 
124
        g_free (xid);
 
125
        return FALSE;
 
126
    }
 
127
    g_free (xid);
 
128
 
 
129
    c->dialog_pid = child_pid;
 
130
    c->dialog_fd = outpipe;
 
131
 
 
132
    channel = g_io_channel_unix_new (c->dialog_fd);
 
133
    g_io_add_watch_full (channel, G_PRIORITY_DEFAULT,
 
134
                         G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
 
135
                         terminateProcessIO,
 
136
                         (gpointer) c, NULL);
 
137
    g_io_channel_unref (channel);
 
138
 
 
139
    return TRUE;
 
140
}
 
141