~3v1n0/compiz/gtk-decorator-finalize-menu-0.9.10

« back to all changes in this revision

Viewing changes to src/session.cpp

src/session.cpp cleanup:

Declaration and assignment of local variables in one line.
(this *should* fix bug #1101405)
Use pre- instead of postfix increments.
Added and removed newlines.
Added missing break (just a style issue).
Fixed indentation.

(LP: #1101405). Fixes: https://bugs.launchpad.net/bugs/1101405.

Approved by PS Jenkins bot, Sam Spilsbury.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#define SM_DEBUG(x)
47
47
 
48
 
static SmcConn           smcConnection;
 
48
static SmcConn           smcConnection;
49
49
static CompWatchFdHandle iceWatchFdHandle;
50
 
static bool              connected = false;
51
 
static bool              iceConnected = false;
 
50
static bool              connected    = false;
 
51
static bool              iceConnected = false;
52
52
static char              *smClientId, *smPrevClientId;
53
53
 
54
54
static void iceInit (void);
55
55
 
56
56
static void
57
 
setStringListProperty (SmcConn    connection,
 
57
setStringListProperty (SmcConn    connection,
58
58
                       const char *name,
59
59
                       const char **values,
60
 
                       int        nValues)
 
60
                       int        nValues)
61
61
{
62
62
    SmProp prop, *pProp;
63
63
 
65
65
    prop.type = const_cast<char *> (SmLISTofARRAY8);
66
66
 
67
67
    prop.vals = (SmPropValue *) malloc (nValues * sizeof (SmPropValue));
 
68
 
68
69
    if (!prop.vals)
69
70
        return;
70
71
 
71
 
    for (int i = 0; i < nValues; i++)
 
72
    for (int i = 0; i < nValues; ++i)
72
73
    {
73
74
        prop.vals[i].value = (char *) values[i];
74
75
        prop.vals[i].length = strlen (values[i]);
86
87
static void
87
88
setCloneRestartCommands (SmcConn connection)
88
89
{
89
 
    const char **args;
90
 
 
91
90
    /* at maximum, we pass our old arguments + our new client id
92
91
       to the SM, so allocate for that case */
93
 
    args = (const char **) malloc ((programArgc + 2) * sizeof (char *));
 
92
    const char **args = (const char **) malloc ((programArgc + 2) * sizeof (char *));
 
93
 
94
94
    if (!args)
95
95
        return;
96
96
 
97
97
    int i, count = 0;
98
98
 
99
 
    for (i = 0; i < programArgc; i++)
 
99
    for (i = 0; i < programArgc; ++i)
100
100
    {
101
101
        if (strcmp (programArgv[i], "--sm-client-id") == 0)
102
 
            i++; /* skip old client id, we'll add the new one later */
 
102
            ++i; /* skip old client id, we'll add the new one later */
103
103
        else if (strcmp (programArgv[i], "--replace") == 0)
104
104
            continue; /* there's nothing to replace when starting session */
105
105
        else
112
112
       position 0 is the executable name */
113
113
    for (i = count - 1; i >= 1; i--)
114
114
        args[i + 2] = args[i];
 
115
 
115
116
    args[1] = "--sm-client-id";
116
117
    args[2] = smClientId;
117
 
    count += 2;
 
118
    count  += 2;
118
119
 
119
120
    setStringListProperty (connection, SmRestartCommand, args, count);
120
121
 
125
126
setRestartStyle (SmcConn connection,
126
127
                 char    hint)
127
128
{
128
 
    SmProp      prop, *pProp;
 
129
    SmProp      prop, *pProp;
129
130
    SmPropValue propVal;
130
131
 
131
 
    prop.name = const_cast<char *> (SmRestartStyleHint);
132
 
    prop.type = const_cast<char *> (SmCARD8);
133
 
    prop.num_vals = 1;
134
 
    prop.vals = &propVal;
135
 
    propVal.value = &hint;
 
132
    prop.name      = const_cast<char *> (SmRestartStyleHint);
 
133
    prop.type      = const_cast<char *> (SmCARD8);
 
134
    prop.num_vals  = 1;
 
135
    prop.vals      = &propVal;
 
136
    propVal.value  = &hint;
136
137
    propVal.length = 1;
137
138
 
138
139
    pProp = &prop;
141
142
}
142
143
 
143
144
static void
144
 
setProgramInfo (SmcConn    connection,
145
 
                pid_t      pid,
146
 
                uid_t      uid)
 
145
setProgramInfo (SmcConn connection,
 
146
                pid_t   pid,
 
147
                uid_t   uid)
147
148
{
148
149
    SmProp        progProp, pidProp, userProp;
149
150
    SmPropValue   progVal, pidVal, userVal;
173
174
    props[count++] = &pidProp;
174
175
 
175
176
    pw = getpwuid (uid);
 
177
 
176
178
    if (pw)
177
179
    {
178
180
        userProp.name     = const_cast<char *> (SmUserID);
189
191
}
190
192
 
191
193
static void
192
 
saveYourselfCallback (SmcConn   connection,
 
194
saveYourselfCallback (SmcConn   connection,
193
195
                      SmPointer client_data,
194
 
                      int       saveType,
195
 
                      Bool      shutdown,
196
 
                      int       interact_Style,
197
 
                      Bool      fast)
 
196
                      int       saveType,
 
197
                      Bool      shutdown,
 
198
                      int       interact_Style,
 
199
                      Bool      fast)
198
200
{
199
201
    CompOption::Vector args;
200
202
 
201
 
    args.push_back (CompOption ("save_type", CompOption::TypeInt));
202
 
    args.push_back (CompOption ("shutdown", CompOption::TypeBool));
 
203
    args.push_back (CompOption ("save_type",      CompOption::TypeInt));
 
204
    args.push_back (CompOption ("shutdown",       CompOption::TypeBool));
203
205
    args.push_back (CompOption ("interact_style", CompOption::TypeInt));
204
 
    args.push_back (CompOption ("fast", CompOption::TypeBool));
 
206
    args.push_back (CompOption ("fast",           CompOption::TypeBool));
205
207
 
206
208
    args[0].value ().set (saveType);
207
209
    args[1].value ().set ((bool) shutdown);
254
256
        callbacks.save_yourself.callback    = saveYourselfCallback;
255
257
        callbacks.save_yourself.client_data = NULL;
256
258
 
257
 
        callbacks.die.callback    = dieCallback;
 
259
        callbacks.die.callback    = dieCallback;
258
260
        callbacks.die.client_data = NULL;
259
261
 
260
262
        callbacks.save_complete.callback    = saveCompleteCallback;
261
263
        callbacks.save_complete.client_data = NULL;
262
264
 
263
 
        callbacks.shutdown_cancelled.callback    = shutdownCancelledCallback;
 
265
        callbacks.shutdown_cancelled.callback    = shutdownCancelledCallback;
264
266
        callbacks.shutdown_cancelled.client_data = NULL;
265
267
 
266
268
        smcConnection = SmcOpenConnection (NULL,
268
270
                                           SmProtoMajor,
269
271
                                           SmProtoMinor,
270
272
                                           SmcSaveYourselfProcMask |
271
 
                                           SmcDieProcMask          |
 
273
                                           SmcDieProcMask          |
272
274
                                           SmcSaveCompleteProcMask |
273
275
                                           SmcShutdownCancelledProcMask,
274
276
                                           &callbacks,
283
285
        else
284
286
        {
285
287
            connected = true;
 
288
 
286
289
            if (prevClientId)
287
290
                smPrevClientId = strdup (prevClientId);
 
291
 
288
292
            setRestartStyle (smcConnection, SmRestartImmediately);
289
 
            
290
293
        }
291
294
    }
292
295
}
306
309
            free (smClientId);
307
310
            smClientId = NULL;
308
311
        }
 
312
 
309
313
        if (smPrevClientId)
310
314
        {
311
315
            free (smPrevClientId);
320
324
    if (!connected)
321
325
        return "";
322
326
 
323
 
    switch (type) {
 
327
    switch (type)
 
328
    {
324
329
        case CompSession::ClientId:
325
330
            if (smClientId)
326
331
                return smClientId;
 
332
 
327
333
            break;
 
334
 
328
335
        case CompSession::PrevClientId:
329
336
            if (smPrevClientId)
330
337
                return smPrevClientId;
 
338
 
 
339
            break;
 
340
 
 
341
        default:
331
342
            break;
332
343
    }
333
344
 
341
352
static bool
342
353
iceProcessMessages (IceConn connection)
343
354
{
344
 
    IceProcessMessagesStatus status;
345
 
 
346
355
    SM_DEBUG (printf ("ICE connection process messages\n"));
347
356
 
348
 
    status = IceProcessMessages (connection, NULL, NULL);
 
357
    IceProcessMessagesStatus status = IceProcessMessages (connection, NULL, NULL);
349
358
 
350
359
    if (status == IceProcessMessagesIOError)
351
360
    {