From aa3cc75d642d0a2b8fb9edf4e0af71b3ab5f660c Mon Sep 17 00:00:00 2001 From: David Nusinow Date: Wed, 26 Mar 2008 19:54:17 -0400 Subject: [PATCH] Fix a segfault when clicking on the monitor list. Thanks Ari Pollak for the patch. Closes: #445310 --- src/callbacks.c | 26 ++++++++++++++------------ src/grandr.c | 29 ++++++++++++++--------------- src/grandr.h | 6 +++--- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/callbacks.c b/src/callbacks.c index f5a4bd4..d419e4f 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -159,8 +159,10 @@ on_modes_combo_changed (GtkComboBox *combobox, GtkTreeIter iter; int mode_id; + if (!gtk_combo_box_get_active_iter (combobox, &iter)) + return; model = gtk_combo_box_get_model (combobox); - gtk_combo_box_get_active_iter (combobox, &iter); + gtk_tree_model_get (model, &iter, COL_MODE_ID, &mode_id, -1); @@ -231,7 +233,7 @@ on_iview_drag_data_get (GtkWidget *widget, GtkTreeIter iter; GList *path_list; GtkTreePath *tree_path; - int output_id; + static int output_id; int i; GtkIconView *iconview = (GtkIconView *) widget; @@ -261,7 +263,7 @@ on_iview_drag_data_get (GtkWidget *widget, &output_id, sizeof (int) ); - gtk_list_store_remove (model, &iter); + gtk_list_store_remove (GTK_LIST_STORE(model), &iter); } @@ -289,9 +291,9 @@ on_iview_drag_data_received (GtkWidget *widget, output_id = (int) *data->data; output_name = get_output_name (screen_info, output_id); - store = gtk_icon_view_get_model (widget); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, + store = gtk_icon_view_get_model (GTK_ICON_VIEW(widget)); + gtk_list_store_append (GTK_LIST_STORE(store), &iter); + gtk_list_store_set (GTK_LIST_STORE(store), &iter, COL_OUTPUT_ID, output_id, COL_OUTPUT_NAME, output_name, COL_OUTPUT_PIXBUF, output_pixbuf, @@ -311,7 +313,7 @@ on_auto_cbtn_toggled (GtkToggleButton *togglebutton, if (gtk_toggle_button_get_active (togglebutton)) { gtk_widget_set_sensitive (mode_combo, FALSE); - gtk_toggle_button_set_active (off_cbtn, FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off_cbtn), FALSE); screen_info->cur_output->auto_set = 1; screen_info->cur_output->off_set = 0; @@ -320,7 +322,7 @@ on_auto_cbtn_toggled (GtkToggleButton *togglebutton, //screen_info->cur_crtc->changed = 1; } else { - if (!gtk_toggle_button_get_active (off_cbtn)) { + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(off_cbtn))) { gtk_widget_set_sensitive (mode_combo, TRUE); } } @@ -339,7 +341,7 @@ on_off_cbtn_toggled (GtkToggleButton *togglebutton, if (gtk_toggle_button_get_active (togglebutton)) { gtk_widget_set_sensitive (mode_combo, FALSE); - gtk_toggle_button_set_active (auto_cbtn, FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(auto_cbtn), FALSE); screen_info->cur_output->auto_set = 0; screen_info->cur_output->off_set = 1; @@ -348,7 +350,7 @@ on_off_cbtn_toggled (GtkToggleButton *togglebutton, //screen_info->cur_crtc->changed = 1; } else { - if (!gtk_toggle_button_get_active (auto_cbtn)) { + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(auto_cbtn))) { gtk_widget_set_sensitive (mode_combo, TRUE); } } @@ -398,8 +400,8 @@ on_about_btn_clicked (GtkButton *button, "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n" "THE SOFTWARE."; - gtk_show_about_dialog (root_window, - "authors", authors, + gtk_show_about_dialog (GTK_WINDOW(root_window), + "authors", authors, "comments", comments, "name", "RandR GUI", "license", license, diff --git a/src/grandr.c b/src/grandr.c index 8f0980b..4cd94e4 100644 --- a/src/grandr.c +++ b/src/grandr.c @@ -23,6 +23,7 @@ #include "support.h" #include "callbacks.h" #include +#include #include static Status crtc_disable (struct CrtcInfo *crtc); @@ -32,7 +33,7 @@ static Status crtc_disable (struct CrtcInfo *crtc); char * get_output_name (struct ScreenInfo *screen_info, RROutput id) { - char *output_name; + char *output_name = NULL; int i; for (i = 0; i < screen_info->n_output; i++) { @@ -51,7 +52,7 @@ get_output_name (struct ScreenInfo *screen_info, RROutput id) XRRModeInfo * find_mode_by_xid (struct ScreenInfo *screen_info, RRMode mode_id) { - XRRModeInfo *mode_info; + XRRModeInfo *mode_info = NULL; XRRScreenResources *res; int i; @@ -213,8 +214,8 @@ set_screen_size (struct ScreenInfo *screen_info) int screen; struct CrtcInfo *crtc; XRRModeInfo *mode_info; - int cur_x, cur_y; - int w, h; + int cur_x = 0, cur_y = 0; + int w = 0, h = 0; int mmW, mmH; int max_width = 0, max_height = 0; int i; @@ -405,7 +406,7 @@ apply (struct ScreenInfo *screen_info) set_positions (screen_info); if (!set_screen_size (screen_info)) { - dialog = gtk_message_dialog_new (root_window, + dialog = gtk_message_dialog_new (GTK_WINDOW(root_window), GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_CANCEL, @@ -650,16 +651,14 @@ fill_output_store (GtkListStore *store, struct ScreenInfo *screen_info, int big_ } -static char * +static gchar * get_mode_name (struct ScreenInfo *screen_info, RRMode mode_id) { XRRScreenResources *sr; - char *mode_name; - int mode_name_len = 40; + gchar *mode_name = NULL; int i; sr = screen_info->res; - mode_name = malloc (mode_name_len); for (i = 0; i < sr->nmode; i++) { if (sr->modes[i].id == mode_id) { @@ -668,16 +667,16 @@ get_mode_name (struct ScreenInfo *screen_info, RRMode mode_id) } if (i == sr->nmode) { - snprintf (mode_name, mode_name_len, "%s", "Unknown mode"); + mode_name = g_strdup ("Unknown mode"); } else { double rate; if (sr->modes[i].hTotal && sr->modes[i].vTotal) { rate = ((double) sr->modes[i].dotClock / ((double) sr->modes[i].hTotal * (double) sr->modes[i].vTotal)); - } else { + } else { rate = 0; } - snprintf (mode_name, mode_name_len, "%s%6.1fHz", sr->modes[i].name, rate); + mode_name = g_strdup_printf ("%s%6.1fHz", sr->modes[i].name, rate); } return mode_name; @@ -730,7 +729,7 @@ fill_mode_store (GtkListStore *store, struct OutputInfo *output) GtkTreeIter iter; XRROutputInfo *output_info; - char *mode_name; + gchar *mode_name; int i; int mode_index = -1; @@ -750,7 +749,7 @@ fill_mode_store (GtkListStore *store, struct OutputInfo *output) COL_MODE_NAME, mode_name, -1); mode_index++; - free (mode_name); + g_free (mode_name); if (output->cur_crtc && output->cur_crtc->cur_mode_id == output_info->modes[i]) { active_num = mode_index; @@ -1190,7 +1189,7 @@ set_positions (struct ScreenInfo *screen_info) GtkWidget *pos_iview[N_POSITIONS]; struct CrtcInfo *crtc_info; RRCrtc *crtc_list; - int list_len; + int list_len = 0; int x, y; int center_x, right_x; int center_y, below_y; diff --git a/src/grandr.h b/src/grandr.h index c00fe1a..861a4fe 100644 --- a/src/grandr.h +++ b/src/grandr.h @@ -83,7 +83,7 @@ extern GtkListStore *output_store; extern GtkListStore *center_store, *left_store, *right_store, *above_store, *below_store; extern GtkListStore *mode_store; extern const guint8 big_pixbuf[], small_pixbuf[]; - +void free_screen_info (struct ScreenInfo *screen_info); GdkPixbuf* randr_create_pixbuf (const guint8 *data); struct ScreenInfo* read_screen_info (Display *); -- 1.6.3.3