1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2014 Red Hat, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 * Author:  Florian Müllner <fmuellner@gnome.org>
 */

#include <stdio.h>
#include <string.h>
#include <glib.h>

#include "wm-button-layout-translation.h"

static void
translate_buttons (char *layout, int *len_p)
{
  char *strp = layout, *button;<--- Variable 'button' can be declared as pointer to const
  int len = 0;

  if (!layout || !*layout)
    goto out;

  while ((button = strsep (&strp, ",")))
    {
      char *ctkbutton;<--- Variable 'ctkbutton' can be declared as pointer to const

      if (strcmp (button, "menu") == 0)
        ctkbutton = "icon";
      else if (strcmp (button, "appmenu") == 0)
        ctkbutton = "menu";
      else if (strcmp (button, "minimize") == 0)
        ctkbutton = "minimize";
      else if (strcmp (button, "maximize") == 0)
        ctkbutton = "maximize";
      else if  (strcmp (button, "close") == 0)
        ctkbutton = "close";
      else
        continue;

      if (len)
        layout[len++] = ',';

      strcpy (layout + len, ctkbutton);
      len += strlen (ctkbutton);
    }
  layout[len] = '\0';

out:
  if (len_p)
    *len_p = len;
}

void
translate_wm_button_layout_to_ctk (char *layout)
{
  char *strp = layout, *left_buttons, *right_buttons;
  int left_len, right_len = 0;

  left_buttons = strsep (&strp, ":");
  right_buttons = strp;

  translate_buttons (left_buttons, &left_len);
  memmove (layout, left_buttons, left_len);

  if (strp == NULL)
    goto out; /* no ":" in layout */

  layout[left_len++] = ':';

  translate_buttons (right_buttons, &right_len);
  memmove (layout + left_len, right_buttons, right_len);

out:
  layout[left_len + right_len] = '\0';
}