summaryrefslogtreecommitdiff
path: root/mate-panel
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2023-11-15 15:10:11 +0100
committerraveit65 <[email protected]>2024-02-04 18:37:58 +0100
commit62fabfc793b545250dafaf37f75650cbfdce095f (patch)
tree813bd86b3926f24be1f17a1830f2f3d65fd4ec8a /mate-panel
parentf98be9734446e1b620312b69dc8fa8ed0f0997d9 (diff)
downloadmate-panel-62fabfc793b545250dafaf37f75650cbfdce095f.tar.bz2
mate-panel-62fabfc793b545250dafaf37f75650cbfdce095f.tar.xz
Reduce scope of variables
Mostly found by cppcheck. origin commit was: https://github.com/mate-desktop/mate-panel/commit/96c7ebc
Diffstat (limited to 'mate-panel')
-rw-r--r--mate-panel/button-widget.c6
-rw-r--r--mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c13
-rw-r--r--mate-panel/libpanel-util/panel-color.c8
-rw-r--r--mate-panel/libpanel-util/panel-gtk.c3
-rw-r--r--mate-panel/libpanel-util/panel-keyfile.c5
-rw-r--r--mate-panel/mate-desktop-item-edit.c3
-rw-r--r--mate-panel/panel-lockdown.c8
-rw-r--r--mate-panel/panel-menu-items.c24
-rw-r--r--mate-panel/panel-multimonitor.c3
-rw-r--r--mate-panel/panel-profile.c4
-rw-r--r--mate-panel/panel-test-applets.c5
-rw-r--r--mate-panel/panel-widget.c2
12 files changed, 37 insertions, 47 deletions
diff --git a/mate-panel/button-widget.c b/mate-panel/button-widget.c
index 43d432a9..00753b99 100644
--- a/mate-panel/button-widget.c
+++ b/mate-panel/button-widget.c
@@ -161,8 +161,6 @@ button_widget_unset_surfaces (ButtonWidget *button)
static void
button_widget_reload_surface (ButtonWidget *button)
{
- GdkDisplay *display;
- gint scale;
button_widget_unset_surfaces (button);
button->priv->needs_move = FALSE;
@@ -170,7 +168,9 @@ button_widget_reload_surface (ButtonWidget *button)
return;
if (button->priv->filename != NULL && button->priv->filename [0] != '\0') {
- char *error = NULL;
+ GdkDisplay *display;
+ gint scale;
+ char *error = NULL;
/* icons findable in the icon theme can be handled by gtk directly*/
display = gdk_display_get_default ();
scale = gtk_widget_get_scale_factor (GTK_WIDGET (button));
diff --git a/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c b/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c
index 115919b0..b65fe4a7 100644
--- a/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c
+++ b/mate-panel/libmate-panel-applet-private/panel-applets-manager-dbus.c
@@ -159,7 +159,6 @@ mate_panel_applets_manager_get_applet_factory_info_from_file (const gchar *filen
{
MatePanelAppletFactoryInfo *info;
GKeyFile *applet_file;
- const char *lib_prefix;
gchar **groups;
gsize n_groups;
gsize i;
@@ -189,6 +188,8 @@ mate_panel_applets_manager_get_applet_factory_info_from_file (const gchar *filen
info->in_process = g_key_file_get_boolean (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP,
"InProcess", NULL);
if (info->in_process) {
+ const char *lib_prefix;
+
info->location = g_key_file_get_string (applet_file, MATE_PANEL_APPLET_FACTORY_GROUP,
"Location", NULL);
if (!info->location) {
@@ -335,15 +336,15 @@ applets_directory_changed (GFileMonitor *monitor,
static void
mate_panel_applets_manager_dbus_load_applet_infos (MatePanelAppletsManagerDBus *manager)
{
- GSList *dirs, *d;
- GDir *dir;
- const gchar *dirent;
- GError *error = NULL;
+ GSList *dirs;
dirs = mate_panel_applets_manager_get_applets_dirs ();
- for (d = dirs; d; d = g_slist_next (d)) {
+ for (GSList *d = dirs; d; d = g_slist_next (d)) {
+ GDir *dir;
+ const gchar *dirent;
GFileMonitor *monitor;
GFile *dir_file;
+ GError *error = NULL;
gchar *path = (gchar *) d->data;
dir = g_dir_open (path, 0, &error);
diff --git a/mate-panel/libpanel-util/panel-color.c b/mate-panel/libpanel-util/panel-color.c
index f6148aaa..661e6fb5 100644
--- a/mate-panel/libpanel-util/panel-color.c
+++ b/mate-panel/libpanel-util/panel-color.c
@@ -17,7 +17,6 @@ rgb_to_hls (gdouble *r, gdouble *g, gdouble *b)
gdouble green;
gdouble blue;
gdouble h, l, s;
- gdouble delta;
red = *r;
green = *g;
@@ -50,6 +49,8 @@ rgb_to_hls (gdouble *r, gdouble *g, gdouble *b)
h = 0;
if (max != min) {
+ gdouble delta;
+
if (l <= 0.5)
s = (max - min) / (max + min);
else
@@ -84,11 +85,9 @@ rgb_to_hls (gdouble *r, gdouble *g, gdouble *b)
static void
hls_to_rgb (gdouble *h, gdouble *l, gdouble *s)
{
- gdouble hue;
gdouble lightness;
gdouble saturation;
gdouble m1, m2;
- gdouble r, g, b;
lightness = *l;
saturation = *s;
@@ -104,6 +103,9 @@ hls_to_rgb (gdouble *h, gdouble *l, gdouble *s)
*l = lightness;
*s = lightness;
} else {
+ gdouble hue;
+ gdouble r, g, b;
+
hue = *h + 120;
while (hue > 360)
hue -= 360;
diff --git a/mate-panel/libpanel-util/panel-gtk.c b/mate-panel/libpanel-util/panel-gtk.c
index d638d75d..3672fca8 100644
--- a/mate-panel/libpanel-util/panel-gtk.c
+++ b/mate-panel/libpanel-util/panel-gtk.c
@@ -119,7 +119,6 @@ panel_file_chooser_dialog_new_valist (const gchar *title,
{
GtkWidget *result;
const char *button_text = first_button_text;
- gint response_id;
result = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
"title", title,
@@ -131,7 +130,7 @@ panel_file_chooser_dialog_new_valist (const gchar *title,
while (button_text)
{
- response_id = va_arg (varargs, gint);
+ gint response_id = va_arg (varargs, gint);
if (g_strcmp0 (button_text, "process-stop") == 0)
panel_dialog_add_button (GTK_DIALOG (result), _("_Cancel"), button_text, response_id);
diff --git a/mate-panel/libpanel-util/panel-keyfile.c b/mate-panel/libpanel-util/panel-keyfile.c
index 0b0104ef..b98058c3 100644
--- a/mate-panel/libpanel-util/panel-keyfile.c
+++ b/mate-panel/libpanel-util/panel-keyfile.c
@@ -53,8 +53,6 @@ _panel_key_file_make_executable (const gchar *path)
{
GFile *file;
GFileInfo *info;
- guint32 current_perms;
- guint32 new_perms;
file = g_file_new_for_path (path);
@@ -72,6 +70,9 @@ _panel_key_file_make_executable (const gchar *path)
}
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) {
+ guint32 current_perms;
+ guint32 new_perms;
+
current_perms = g_file_info_get_attribute_uint32 (info,
G_FILE_ATTRIBUTE_UNIX_MODE);
new_perms = current_perms | S_IXGRP | S_IXUSR | S_IXOTH;
diff --git a/mate-panel/mate-desktop-item-edit.c b/mate-panel/mate-desktop-item-edit.c
index b0912405..b37f43ed 100644
--- a/mate-panel/mate-desktop-item-edit.c
+++ b/mate-panel/mate-desktop-item-edit.c
@@ -123,7 +123,6 @@ main (int argc, char * argv[])
for (i = 0; desktops[i] != NULL; i++) {
GFile *file;
GFileInfo *info;
- GFileType type;
char *uri;
char *path;
GtkWidget *dlg = NULL;
@@ -136,7 +135,7 @@ main (int argc, char * argv[])
g_object_unref (file);
if (info) {
- type = g_file_info_get_file_type (info);
+ GFileType type = g_file_info_get_file_type (info);
if (type == G_FILE_TYPE_DIRECTORY && create_new) {
diff --git a/mate-panel/panel-lockdown.c b/mate-panel/panel-lockdown.c
index 16648ee3..8750be81 100644
--- a/mate-panel/panel-lockdown.c
+++ b/mate-panel/panel-lockdown.c
@@ -269,12 +269,10 @@ panel_lockdown_get_disable_force_quit (void)
gboolean
panel_lockdown_is_applet_disabled (const char *iid)
{
- gint i;
-
g_assert (panel_lockdown.initialized != FALSE);
if (panel_lockdown.disabled_applets)
- for (i = 0; panel_lockdown.disabled_applets[i]; i++)
+ for (gint i = 0; panel_lockdown.disabled_applets[i]; i++)
if (!strcmp (panel_lockdown.disabled_applets[i], iid))
return TRUE;
@@ -286,9 +284,7 @@ panel_lockdown_notify_find (GSList *closures,
GCallback callback_func,
gpointer user_data)
{
- GSList *l;
-
- for (l = closures; l; l = l->next) {
+ for (GSList *l = closures; l; l = l->next) {
GCClosure *cclosure = l->data;
GClosure *closure = l->data;
diff --git a/mate-panel/panel-menu-items.c b/mate-panel/panel-menu-items.c
index 05af4969..14b58701 100644
--- a/mate-panel/panel-menu-items.c
+++ b/mate-panel/panel-menu-items.c
@@ -143,7 +143,6 @@ panel_menu_items_append_from_desktop (GtkWidget *menu,
char *uri;
char *type;
gboolean is_application;
- char *tryexec;
char *icon;
char *name;
char *comment;
@@ -198,7 +197,7 @@ panel_menu_items_append_from_desktop (GtkWidget *menu,
g_free (type);
if (is_application) {
- tryexec = panel_key_file_get_string (key_file, "TryExec");
+ char *tryexec = panel_key_file_get_string (key_file, "TryExec");
if (tryexec) {
char *prog;
@@ -409,7 +408,6 @@ panel_place_menu_item_append_gtk_bookmarks (GtkWidget *menu, guint max_items_or_
char *line = (char*) l->data;
if (line[0] && !g_hash_table_lookup (table, line)) {
- GFile *file;
char *space;
char *label;
gboolean keep;
@@ -430,7 +428,7 @@ panel_place_menu_item_append_gtk_bookmarks (GtkWidget *menu, guint max_items_or_
keep = TRUE;
if (!keep) {
- file = g_file_new_for_uri (line);
+ GFile *file = g_file_new_for_uri (line);
keep = !g_file_is_native (file) ||
g_file_query_exists (file, NULL);
g_object_unref (file);
@@ -544,15 +542,16 @@ drive_poll_for_media_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- GdkScreen *screen;
- GError *error;
- char *primary;
- char *name;
+ GError *error;
error = NULL;
if (!g_drive_poll_for_media_finish (G_DRIVE (source_object),
res, &error)) {
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
+ GdkScreen *screen;
+ char *primary;
+ char *name;
+
screen = GDK_SCREEN (user_data);
name = g_drive_get_name (G_DRIVE (source_object));
@@ -633,10 +632,10 @@ volume_mount_cb (GObject *source_object,
error = NULL;
if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) {
- char *primary;
- char *name;
-
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
+ char *primary;
+ char *name;
+
name = g_volume_get_name (G_VOLUME (source_object));
primary = g_strdup_printf (_("Unable to mount %s"),
name);
@@ -1019,7 +1018,6 @@ static GtkWidget *
panel_place_menu_item_create_menu (PanelPlaceMenuItem *place_item)
{
GtkWidget *places_menu;
- GtkWidget *item;
char *gsettings_name = NULL;
char *name;
char *uri;
@@ -1101,7 +1099,7 @@ panel_place_menu_item_create_menu (PanelPlaceMenuItem *place_item)
if (panel_is_program_in_path ("caja-connect-server") ||
panel_is_program_in_path ("nautilus-connect-server") ||
panel_is_program_in_path ("nemo-connect-server")) {
- item = panel_menu_items_create_action_item (PANEL_ACTION_CONNECT_SERVER);
+ GtkWidget *item = panel_menu_items_create_action_item (PANEL_ACTION_CONNECT_SERVER);
if (item != NULL)
gtk_menu_shell_append (GTK_MENU_SHELL (places_menu),
item);
diff --git a/mate-panel/panel-multimonitor.c b/mate-panel/panel-multimonitor.c
index b2723f12..c7ac14cc 100644
--- a/mate-panel/panel-multimonitor.c
+++ b/mate-panel/panel-multimonitor.c
@@ -71,7 +71,6 @@ _panel_multimonitor_output_should_be_first (Display *xdisplay,
unsigned long nitems;
unsigned long bytes_after;
unsigned char *prop;
- gboolean retval;
connector_type_atom = XInternAtom (xdisplay, "ConnectorType", False);
@@ -81,7 +80,7 @@ _panel_multimonitor_output_should_be_first (Display *xdisplay,
&nitems, &bytes_after, &prop) == Success) {
if (actual_type == XA_ATOM && nitems == 1 && actual_format == 32) {
char *connector_type = XGetAtomName (xdisplay, prop[0]);
- retval = g_strcmp0 (connector_type, "Panel") == 0;
+ gboolean retval = g_strcmp0 (connector_type, "Panel") == 0;
XFree (connector_type);
return retval;
}
diff --git a/mate-panel/panel-profile.c b/mate-panel/panel-profile.c
index 5f1013f1..06d096c2 100644
--- a/mate-panel/panel-profile.c
+++ b/mate-panel/panel-profile.c
@@ -1583,11 +1583,9 @@ panel_profile_load_list (GSettings *settings,
PanelProfileLoadFunc load_handler,
GCallback notify_handler)
{
-
const gchar *key = key_from_type (type);
gchar *changed_signal;
gchar **list;
- gint i;
changed_signal = g_strdup_printf ("changed::%s", key);
g_signal_connect (settings, changed_signal, G_CALLBACK (notify_handler), NULL);
@@ -1595,7 +1593,7 @@ panel_profile_load_list (GSettings *settings,
list = g_settings_get_strv (settings, key);
- for (i = 0; list[i]; i++) {
+ for (gint i = 0; list[i]; i++) {
load_handler (list[i]);
}
diff --git a/mate-panel/panel-test-applets.c b/mate-panel/panel-test-applets.c
index f14c3888..79b48d36 100644
--- a/mate-panel/panel-test-applets.c
+++ b/mate-panel/panel-test-applets.c
@@ -178,13 +178,12 @@ static void
load_applet_from_command_line (void)
{
guint size = 24, orient = PANEL_ORIENTATION_TOP;
- gsize i;
g_assert (cli_iid != NULL);
if (cli_size || cli_orient) {
if (cli_size) {
- for (i = 0; i < G_N_ELEMENTS (size_items); i++) {
+ for (gsize i = 0; i < G_N_ELEMENTS (size_items); i++) {
if (strcmp (g_dpgettext2 (NULL, "Size", size_items[i].name), cli_size) == 0) {
size = size_items[i].value;
break;
@@ -193,7 +192,7 @@ load_applet_from_command_line (void)
}
if (cli_orient) {
- for (i = 0; i < G_N_ELEMENTS (orient_items); i++) {
+ for (gsize i = 0; i < G_N_ELEMENTS (orient_items); i++) {
if (strcmp (g_dpgettext2 (NULL, "Orientation", orient_items[i].name), cli_orient) == 0) {
orient = orient_items[i].value;
break;
diff --git a/mate-panel/panel-widget.c b/mate-panel/panel-widget.c
index a8c01854..ebaf74bf 100644
--- a/mate-panel/panel-widget.c
+++ b/mate-panel/panel-widget.c
@@ -1449,7 +1449,6 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
list = g_list_next (list)) {
AppletData *ad = list->data;
GtkRequisition chreq;
-
gtk_widget_get_preferred_size (ad->applet, &chreq, NULL);
if (!ad->expand_major || !ad->size_hints) {
@@ -1465,7 +1464,6 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
}
ad->constrained = ad->pos;
-
if (ad->constrained < i)
ad->constrained = i;