~ps-jenkins/bamf/latestsnapshot-0.4.0daily13.06.1913.04-0ubuntu1

« back to all changes in this revision

Viewing changes to src/bamf-matcher.c

BamfMatcher: use role and class changes signal to match LibreOffice and g-c-c. Fixes: https://bugs.launchpad.net/bugs/1100554.

Approved by Andrea Azzarone, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
337
337
    }
338
338
}
339
339
 
340
 
static char *
341
 
get_open_office_window_hint (BamfMatcher * self, BamfLegacyWindow * window)
 
340
static const char *
 
341
get_libreoffice_window_hint (BamfMatcher * self, BamfLegacyWindow * window)
342
342
{
343
343
  gchar *exec = NULL;
344
 
  const gchar *name;
345
344
  const gchar *class;
346
345
  const char *binary = NULL;
347
346
  const char *parameter = NULL;
348
 
  BamfWindowType type;
 
347
  GList *l = NULL;
349
348
 
350
349
  g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
351
350
  g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);
352
351
 
353
 
  name = bamf_legacy_window_get_name (window);
354
352
  class = bamf_legacy_window_get_class_name (window);
355
 
  type = bamf_legacy_window_get_window_type (window);
356
 
 
357
 
  if (name == NULL && class == NULL)
358
 
    return NULL;
359
 
 
360
 
  if (g_str_has_suffix (name, "LibreOffice Writer"))
361
 
    {
362
 
      binary = "libreoffice";
363
 
      parameter = "writer";
364
 
    }
365
 
  else if (g_str_has_suffix (name, "LibreOffice Calc"))
366
 
    {
367
 
      binary = "libreoffice";
368
 
      parameter = "calc";
369
 
    }
370
 
  else if (g_str_has_suffix (name, "LibreOffice Impress"))
371
 
    {
372
 
      binary = "libreoffice";
373
 
      parameter = "impress";
374
 
    }
375
 
  else if (g_str_has_suffix (name, "LibreOffice Math"))
376
 
    {
377
 
      binary = "libreoffice";
378
 
      parameter = "math";
379
 
    }
380
 
  else if (g_str_has_suffix (name, "LibreOffice Draw"))
381
 
    {
382
 
      binary = "libreoffice";
383
 
      parameter = "draw";
384
 
    }
385
 
  else if (g_str_has_suffix (name, "LibreOffice Base"))
386
 
    {
387
 
      binary = "libreoffice";
388
 
      parameter = "base";
389
 
    }
390
 
  else if (g_strcmp0 (class, "libreoffice-startcenter") == 0)
391
 
    {
392
 
      binary = "libreoffice";
393
 
    }
394
 
  else if (g_strcmp0 (name, "LibreOffice") == 0 && type == BAMF_WINDOW_NORMAL)
395
 
    {
396
 
      binary = "libreoffice";
397
 
    }
398
 
  else if (g_str_has_suffix (name, "OpenOffice.org Writer"))
399
 
    {
400
 
      binary = "ooffice";
401
 
      parameter = "writer";
402
 
    }
403
 
  else if (g_str_has_suffix (name, "OpenOffice.org Calc"))
404
 
    {
405
 
      binary = "ooffice";
406
 
      parameter = "calc";
407
 
    }
408
 
  else if (g_str_has_suffix (name, "OpenOffice.org Impress"))
409
 
    {
410
 
      binary = "ooffice";
411
 
      parameter = "impress";
412
 
    }
413
 
  else if (g_str_has_suffix (name, "OpenOffice.org Math"))
414
 
    {
415
 
      binary = "ooffice";
416
 
      parameter = "math";
417
 
    }
418
 
  else if (g_str_has_suffix (name, "OpenOffice.org Draw"))
419
 
    {
420
 
      binary = "ooffice";
421
 
      parameter = "draw";
422
 
    }
423
 
  else if (g_str_has_suffix (name, "OpenOffice.org Base"))
424
 
    {
425
 
      binary = "ooffice";
426
 
      parameter = "base";
427
 
    }
428
 
  else if (g_strcmp0 (name, "OpenOffice.org") == 0 && type == BAMF_WINDOW_NORMAL)
429
 
    {
430
 
      binary = "ooffice";
431
 
    }
432
 
  else
433
 
    {
434
 
      if (type != BAMF_WINDOW_NORMAL || bamf_legacy_window_get_transient (window))
435
 
      {
436
 
        /* Child windows can generally easily be recognized by their class */
437
 
        if (g_strcmp0 (class, "libreoffice-writer") == 0)
438
 
          {
439
 
            binary = "libreoffice";
440
 
            parameter = "writer";
441
 
          }
442
 
        else if (g_strcmp0 (class, "libreoffice-calc") == 0)
443
 
          {
444
 
            binary = "libreoffice";
445
 
            parameter = "calc";
446
 
          }
447
 
        else if (g_strcmp0 (class, "libreoffice-impress") == 0)
448
 
          {
449
 
            binary = "libreoffice";
450
 
            parameter = "impress";
451
 
          }
452
 
        else if (g_strcmp0 (class, "libreoffice-math") == 0)
453
 
          {
454
 
            binary = "libreoffice";
455
 
            parameter = "math";
456
 
          }
457
 
        else if (g_strcmp0 (class, "libreoffice-draw") == 0)
458
 
          {
459
 
            binary = "libreoffice";
460
 
            parameter = "draw";
461
 
          }
462
 
        else if (g_strcmp0 (class, "libreoffice-base") == 0)
463
 
          {
464
 
            binary = "libreoffice";
465
 
            parameter = "base";
466
 
          }
467
 
      }
468
 
 
469
 
      if (!binary)
470
 
        {
471
 
          /* By default fallback to the main launcher */
472
 
          if (g_str_has_prefix (class, "OpenOffice"))
473
 
            {
474
 
              binary = "ooffice";
475
 
            }
476
 
          else
477
 
            {
478
 
              binary = "libreoffice";
479
 
            }
480
 
        }
481
 
    }
482
 
 
483
 
  if (!binary)
484
 
    return NULL;
485
 
 
486
 
  GList *l = NULL;
487
 
 
488
 
  if (parameter)
489
 
    {
490
 
      exec = g_strconcat (binary, " --", parameter, NULL);
491
 
      l = g_hash_table_lookup (self->priv->desktop_file_table, exec);
492
 
      g_free (exec);
493
 
 
494
 
      if (!l)
495
 
        {
496
 
          exec = g_strconcat (binary, " -", parameter, NULL);
497
 
          l = g_hash_table_lookup (self->priv->desktop_file_table, exec);
498
 
          g_free (exec);
499
 
 
500
 
          if (!l)
501
 
            {
502
 
              exec = g_strconcat (binary, "-", parameter, NULL);
503
 
              l = g_hash_table_lookup (self->priv->desktop_id_table, exec);
504
 
              g_free (exec);
505
 
            }
506
 
        }
507
 
    }
508
 
  else
509
 
    {
510
 
      l = g_hash_table_lookup (self->priv->desktop_file_table, binary);
 
353
 
 
354
  if (!class)
 
355
    return NULL;
 
356
 
 
357
  if (g_str_has_prefix (class, "libreoffice-"))
 
358
    {
 
359
      l = g_hash_table_lookup (self->priv->desktop_id_table, class);
 
360
    }
 
361
 
 
362
  if (!l)
 
363
    {
 
364
      binary = "libreoffice";
 
365
 
 
366
      parameter = strchr(class, '-');
 
367
 
 
368
      if (parameter)
 
369
      {
 
370
        parameter = parameter + 1;
 
371
 
 
372
        exec = g_strconcat (binary, " --", parameter, NULL);
 
373
        l = g_hash_table_lookup (self->priv->desktop_file_table, exec);
 
374
        g_free (exec);
 
375
 
 
376
        if (!l)
 
377
          {
 
378
            exec = g_strconcat (binary, " -", parameter, NULL);
 
379
            l = g_hash_table_lookup (self->priv->desktop_file_table, exec);
 
380
            g_free (exec);
 
381
 
 
382
            if (!l)
 
383
              {
 
384
                exec = g_strconcat (binary, "-", parameter, NULL);
 
385
                l = g_hash_table_lookup (self->priv->desktop_id_table, exec);
 
386
                g_free (exec);
 
387
              }
 
388
          }
 
389
      }
 
390
    else
 
391
      {
 
392
        l = g_hash_table_lookup (self->priv->desktop_file_table, binary);
 
393
      }
511
394
    }
512
395
 
513
396
  return (l ? (char *) l->data : NULL);
1507
1390
}
1508
1391
 
1509
1392
static gboolean
1510
 
is_open_office_window (BamfMatcher * self, BamfLegacyWindow * window)
 
1393
is_libreoffice_window (BamfMatcher * self, BamfLegacyWindow * window)
1511
1394
{
1512
1395
  const char *class_name = bamf_legacy_window_get_class_name (window);
1513
1396
 
2131
2014
}
2132
2015
 
2133
2016
static void
2134
 
on_open_office_window_name_changed (BamfLegacyWindow *window, BamfMatcher* self)
 
2017
on_libreoffice_window_class_changed (BamfLegacyWindow *window, BamfMatcher* self)
2135
2018
{
2136
2019
  g_return_if_fail (BAMF_IS_MATCHER (self));
2137
2020
  g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
2140
2023
  const char *new_hint;
2141
2024
 
2142
2025
  old_hint = bamf_legacy_window_get_hint (window, _NET_WM_DESKTOP_FILE);
2143
 
  new_hint = get_open_office_window_hint (self, window);
 
2026
  new_hint = get_libreoffice_window_hint (self, window);
2144
2027
 
2145
2028
  if (new_hint && g_strcmp0 (new_hint, old_hint) != 0)
2146
2029
    {
2151
2034
}
2152
2035
 
2153
2036
static void
2154
 
on_open_office_window_closed (BamfLegacyWindow *window, BamfMatcher* self)
 
2037
on_libreoffice_window_closed (BamfLegacyWindow *window, BamfMatcher* self)
2155
2038
{
2156
 
  g_signal_handlers_disconnect_by_func (window, on_open_office_window_name_changed, self);
 
2039
  g_signal_handlers_disconnect_by_func (window, on_libreoffice_window_class_changed, self);
2157
2040
  g_object_unref (window);
2158
2041
}
2159
2042
 
2160
2043
static char *
2161
2044
get_gnome_control_center_window_hint (BamfMatcher * self, BamfLegacyWindow * window)
2162
2045
{
2163
 
  gchar *role;
 
2046
  const gchar *role;
2164
2047
  GList *list;
2165
2048
 
2166
2049
  g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
2167
2050
  g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);
2168
2051
 
2169
 
  role = bamf_legacy_window_get_hint (window, WM_WINDOW_ROLE);
 
2052
  role = bamf_legacy_window_get_role (window);
2170
2053
 
2171
2054
  if (role)
2172
2055
    {
2173
2056
      gchar *exec = g_strconcat ("gnome-control-center ", role, NULL);
2174
2057
      list = g_hash_table_lookup (self->priv->desktop_file_table, exec);
2175
2058
      g_free (exec);
2176
 
      g_free (role);
2177
2059
    }
2178
2060
 
2179
2061
  if (!role || !list)
2185
2067
}
2186
2068
 
2187
2069
static void
2188
 
on_gnome_control_center_window_name_changed (BamfLegacyWindow *window, BamfMatcher* self)
 
2070
on_gnome_control_center_window_role_changed (BamfLegacyWindow *window, BamfMatcher* self)
2189
2071
{
2190
2072
  g_return_if_fail (BAMF_IS_MATCHER (self));
2191
2073
  g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
2207
2089
static void
2208
2090
on_gnome_control_center_window_closed (BamfLegacyWindow *window, BamfMatcher* self)
2209
2091
{
2210
 
  g_signal_handlers_disconnect_by_func (window, on_gnome_control_center_window_name_changed, self);
 
2092
  g_signal_handlers_disconnect_by_func (window, on_gnome_control_center_window_role_changed, self);
2211
2093
  g_object_unref (window);
2212
2094
}
2213
2095
 
2226
2108
      return;
2227
2109
    }
2228
2110
 
2229
 
  if (is_open_office_window (self, window))
 
2111
  if (is_libreoffice_window (self, window))
2230
2112
    {
2231
2113
      if (win_type == BAMF_WINDOW_SPLASHSCREEN || win_type == BAMF_WINDOW_TOOLBAR)
2232
2114
        {
2234
2116
        }
2235
2117
 
2236
2118
      char *old_hint = bamf_legacy_window_get_hint (window, _NET_WM_DESKTOP_FILE);
2237
 
      const char *new_hint = get_open_office_window_hint (self, window);
 
2119
      const char *new_hint = get_libreoffice_window_hint (self, window);
2238
2120
 
2239
2121
      if (new_hint && g_strcmp0 (old_hint, new_hint) != 0)
2240
2122
        {
2242
2124
        }
2243
2125
 
2244
2126
      g_object_ref (window);
2245
 
      g_signal_connect (window, "name-changed", (GCallback) on_open_office_window_name_changed, self);
2246
 
      g_signal_connect (window, "closed", (GCallback) on_open_office_window_closed, self);
 
2127
      g_signal_connect (window, "class-changed", (GCallback) on_libreoffice_window_class_changed, self);
 
2128
      g_signal_connect (window, "closed", (GCallback) on_libreoffice_window_closed, self);
2247
2129
 
2248
2130
      g_free (old_hint);
2249
2131
    }
2258
2140
        }
2259
2141
 
2260
2142
      g_object_ref (window);
2261
 
      g_signal_connect (window, "name-changed", (GCallback) on_gnome_control_center_window_name_changed, self);
 
2143
      g_signal_connect (window, "role-changed", (GCallback) on_gnome_control_center_window_role_changed, self);
2262
2144
      g_signal_connect (window, "closed", (GCallback) on_gnome_control_center_window_closed, self);
2263
2145
 
2264
2146
      g_free (old_hint);