예제 #1
0
static void
gy_window_settings__window_realize (GtkWindow *window)
{
  GdkRectangle geom      = { 0 };
  gboolean     maximized = FALSE;

  g_assert (GTK_IS_WINDOW (window));
  g_assert (G_IS_SETTINGS (settings));

  g_settings_get (settings, "window-position", "(ii)", &geom.x, &geom.y);
  g_settings_get (settings, "window-size", "(ii)", &geom.width, &geom.height);
  g_settings_get (settings, "window-maximized", "b", &maximized);

  gtk_window_set_default_size (window, geom.width, geom.height);

  gtk_window_move (window, geom.x, geom.y);

  if (maximized)
    gtk_window_maximize (window);

  DzlDockBin* dockbin = gy_window_get_dockbin (GY_WINDOW (window));
  GtkWidget * edge = dzl_dock_bin_get_left_edge (dockbin);

  g_settings_bind (settings, "left-panel-visible", edge, "reveal-child", G_SETTINGS_BIND_DEFAULT);
  g_settings_bind (settings, "left-panel-position", edge, "position", G_SETTINGS_BIND_DEFAULT);

  edge = dzl_dock_bin_get_right_edge (dockbin);

  g_settings_bind (settings, "right-panel-visible", edge, "reveal-child", G_SETTINGS_BIND_DEFAULT);
  g_settings_bind (settings, "right-panel-position", edge, "position", G_SETTINGS_BIND_DEFAULT);


}
예제 #2
0
파일: plugin.c 프로젝트: VujinovM/anjuta
static void
refresh_recent_project_view (GtkListBox *box)
{
	GSettings *settings;
	GtkRecentManager *manager;
	GtkRecentData *recent_project;
	GList *items, *list;
	gint i;
	guint recent_limit;

	manager = gtk_recent_manager_get_default ();
	items = gtk_recent_manager_get_items (manager);
	items = g_list_reverse (items);
	list = items;
	settings = g_settings_new (PREF_SCHEMA);
	i = 0;
	g_settings_get (settings, RECENT_LIMIT, "i", &recent_limit);
	while (i < recent_limit && list != NULL)
	{
		if (strcmp (gtk_recent_info_get_mime_type (list->data), "application/x-anjuta") == 0)
		{
			recent_project = list->data;
			add_recent_project_row (box, recent_project);
			i++;
		}
		list = list->next;
	}
	g_list_free_full(items, (GDestroyNotify)gtk_recent_info_unref);
	g_object_unref (settings);
}
예제 #3
0
/**
 * gucharma_settings_add_window:
 * @window: a #GtkWindow
 *
 * Restore the window configuration, and persist changes to the window configuration:
 * window width and height, and maximised and fullscreen state.
 * @window must not be realised yet.
 */
void
gucharmap_settings_add_window (GtkWindow *window)
{
  WindowState *state;
  int width, height;
  gboolean maximised, fullscreen;

  g_return_if_fail (GTK_IS_WINDOW (window));
  g_return_if_fail (!gtk_widget_get_realized (GTK_WIDGET (window)));

  state = g_slice_new0 (WindowState);
  state->settings = g_settings_new ("org.gnome.Charmap.WindowState");
  g_object_set_data_full (G_OBJECT (window), "GamesConf::WindowState",
                          state, (GDestroyNotify) free_window_state);

  g_signal_connect_after (window, "size-allocate",
                          G_CALLBACK (window_size_allocate_cb), state);
  g_signal_connect (window, "window-state-event",
                    G_CALLBACK (window_state_event_cb), state);

  maximised = g_settings_get_boolean (state->settings, "maximized");
  fullscreen = g_settings_get_boolean (state->settings, "fullscreen");
  g_settings_get (state->settings, "size", "(ii)", &width, &height);

  if (width > 0 && height > 0) {
    gtk_window_set_default_size (GTK_WINDOW (window), width, height);
  }
  if (maximised) {
    gtk_window_maximize (GTK_WINDOW (window));
  }
  if (fullscreen) {
    gtk_window_fullscreen (GTK_WINDOW (window));
  }
}
예제 #4
0
/* The GeditRecentConfiguration struct is allocated and owned by the caller */
void
gedit_recent_configuration_init_default (GeditRecentConfiguration *config)
{
    GSettings *settings;

    config->manager = gtk_recent_manager_get_default ();

    if (config->filter != NULL)
    {
        g_object_unref (config->filter);
    }

    config->filter = gtk_recent_filter_new ();
    gtk_recent_filter_add_application (config->filter, g_get_application_name ());
    gtk_recent_filter_add_mime_type (config->filter, "text/plain");
    g_object_ref_sink (config->filter);

    settings = g_settings_new ("org.gnome.gedit.preferences.ui");

    g_settings_get (settings,
                    GEDIT_SETTINGS_MAX_RECENTS,
                    "u",
                    &config->limit);

    g_object_unref (settings);

    config->show_not_found = TRUE;
    config->show_private = FALSE;
    config->local_only = FALSE;

    config->substring_filter = NULL;
}
예제 #5
0
gboolean w_settings_get_window_size(wSettings *sett, gint *w, gint *h)
{
	g_return_val_if_fail( sett != NULL && w != NULL && h != NULL, FALSE);

	g_settings_get(G_SETTINGS(sett), "window-size", "(ii)", w, h);

	return TRUE;
}
예제 #6
0
gboolean w_settings_get_window_pos(wSettings *sett, gint *x, gint *y)
{
	g_return_val_if_fail( sett != NULL && x != NULL && y != NULL, FALSE);

	g_settings_get(G_SETTINGS(sett), "window-pos", "(ii)", x, y);

	return TRUE;
}
예제 #7
0
static void
sp_window_settings__window_realize (GtkWindow *window)
{
  GtkApplication *app;
  GdkRectangle geom = { 0 };
  gboolean maximized = FALSE;
  GList *list;
  guint count = 0;

  g_assert (GTK_IS_WINDOW (window));
  g_assert (G_IS_SETTINGS (settings));

  g_settings_get (settings, "window-position", "(ii)", &geom.x, &geom.y);
  g_settings_get (settings, "window-size", "(ii)", &geom.width, &geom.height);
  g_settings_get (settings, "window-maximized", "b", &maximized);

  geom.width = MAX (geom.width, WINDOW_MIN_WIDTH);
  geom.height = MAX (geom.height, WINDOW_MIN_HEIGHT);
  gtk_window_set_default_size (window, geom.width, geom.height);

  /*
   * If there are other windows currently visible other than this one,
   * then ignore positioning and let the window manager decide.
   */
  count = 0;
  app = GTK_APPLICATION (g_application_get_default ());
  list = gtk_application_get_windows (app);
  for (; list != NULL; list = list->next)
    {
      GtkWindow *ele = list->data;

      if (SP_IS_WINDOW (ele) && (ele != window) &&
          gtk_widget_get_visible (GTK_WIDGET (window)))
        count++;
    }

  if (count == 0)
    gtk_window_move (window, geom.x, geom.y);

  if (maximized)
    gtk_window_maximize (window);
}
예제 #8
0
/**
 * gedit_app_create_window:
 * @app: the #GeditApp
 * @screen: (allow-none):
 *
 * Create a new #GeditWindow part of @app.
 *
 * Return value: (transfer none): the new #GeditWindow
 */
GeditWindow *
gedit_app_create_window (GeditApp  *app,
			 GdkScreen *screen)
{
	GeditAppPrivate *priv;
	GeditWindow *window;
	gchar *role;
	GdkWindowState state;
	gint w, h;

	gedit_debug (DEBUG_APP);

	priv = gedit_app_get_instance_private (app);

	window = GEDIT_APP_GET_CLASS (app)->create_window (app);

	if (screen != NULL)
	{
		gtk_window_set_screen (GTK_WINDOW (window), screen);
	}

	role = gen_role ();
	gtk_window_set_role (GTK_WINDOW (window), role);
	g_free (role);

	state = g_settings_get_int (priv->window_settings,
	                            GEDIT_SETTINGS_WINDOW_STATE);

	g_settings_get (priv->window_settings,
	                GEDIT_SETTINGS_WINDOW_SIZE,
	                "(ii)", &w, &h);

	gtk_window_set_default_size (GTK_WINDOW (window), w, h);

	if ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0)
	{
		gtk_window_maximize (GTK_WINDOW (window));
	}
	else
	{
		gtk_window_unmaximize (GTK_WINDOW (window));
	}

	if ((state & GDK_WINDOW_STATE_STICKY ) != 0)
	{
		gtk_window_stick (GTK_WINDOW (window));
	}
	else
	{
		gtk_window_unstick (GTK_WINDOW (window));
	}

	return window;
}
예제 #9
0
void
setup_camera (CheeseWidget *widget)
{
  CheeseWidgetPrivate *priv          = CHEESE_WIDGET_GET_PRIVATE (widget);
  char                *webcam_device = NULL;
  int                  x_resolution;
  int                  y_resolution;
  gdouble              brightness;
  gdouble              contrast;
  gdouble              saturation;
  gdouble              hue;

  g_settings_get (priv->settings, "photo-x-resolution", "i", &x_resolution);
  g_settings_get (priv->settings, "photo-y-resolution", "i", &y_resolution);
  g_settings_get (priv->settings, "camera",       "s", &webcam_device);
  g_settings_get (priv->settings, "brightness",   "d", &brightness);
  g_settings_get (priv->settings, "contrast",     "d", &contrast);
  g_settings_get (priv->settings, "saturation",   "d", &saturation);
  g_settings_get (priv->settings, "hue",          "d", &hue);

  gdk_threads_enter ();
  priv->webcam = cheese_camera_new (CLUTTER_TEXTURE (priv->texture),
                                    webcam_device,
                                    x_resolution,
                                    y_resolution);
  gdk_threads_leave ();

  g_free (webcam_device);

  cheese_camera_setup (priv->webcam, NULL, &priv->error);

  gdk_threads_enter ();

  gtk_spinner_stop (GTK_SPINNER (priv->spinner));

  if (priv->error != NULL)
  {
    priv->state = CHEESE_WIDGET_STATE_ERROR;
    g_object_notify (G_OBJECT (widget), "state");
    cheese_widget_set_problem_page (CHEESE_WIDGET (widget), "error");
  }
  else
  {
    cheese_camera_set_balance_property (priv->webcam, "brightness", brightness);
    cheese_camera_set_balance_property (priv->webcam, "contrast", contrast);
    cheese_camera_set_balance_property (priv->webcam, "saturation", saturation);
    cheese_camera_set_balance_property (priv->webcam, "hue", hue);
    priv->state = CHEESE_WIDGET_STATE_READY;
    g_object_notify (G_OBJECT (widget), "state");
    cheese_camera_play (priv->webcam);
    gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WEBCAM_PAGE);
  }

  gdk_threads_leave ();
}
예제 #10
0
static void
gb_settings__window_realize (GtkWindow *window,
                             GSettings *settings)
{
  GdkRectangle geom = { 0 };
  gboolean maximized = FALSE;

  g_assert (GTK_IS_WINDOW (window));
  g_assert (G_IS_SETTINGS (gSettings));

  g_settings_get (gSettings, "window-position", "(ii)", &geom.x, &geom.y);
  g_settings_get (gSettings, "window-size", "(ii)", &geom.width, &geom.height);
  g_settings_get (gSettings, "window-maximized", "b", &maximized);

  geom.width = MAX (geom.width, GB_WINDOW_MIN_WIDTH);
  geom.height = MAX (geom.height, GB_WINDOW_MIN_HEIGHT);
  gtk_window_set_default_size (window, geom.width, geom.height);

  gtk_window_move (window, geom.x, geom.y);

  if (maximized)
    gtk_window_maximize (window);
}
static void
children_changed (GSettings            *settings,
                  const char           *key,
                  CcNotificationsPanel *panel)
{
  int i;
  const gchar **new_app_ids;

  g_settings_get (panel->master_settings,
                  "application-children",
                  "^a&s", &new_app_ids);
  for (i = 0; new_app_ids[i]; i++)
    maybe_add_app_id (panel, new_app_ids[i]);

  g_free (new_app_ids);
}
  void UpdateDPI()
  {
    auto* uscreen = UScreen::GetDefault();
    double min_scale = 4.0;
    double max_scale = 0.0;
    bool any_changed = false;

    glib::Variant dict;
    g_settings_get(ubuntu_ui_settings_, SCALE_FACTOR.c_str(), "@a{si}", &dict);

    glib::String app_target_monitor(g_settings_get_string(ui_settings_, APP_SCALE_MONITOR.c_str()));
    double app_target_scale = 0;

    for (unsigned monitor = 0; monitor < em_converters_.size(); ++monitor)
    {
      int dpi = DEFAULT_DPI;

      if (monitor < uscreen->GetMonitors().size())
      {
        auto const& monitor_name = uscreen->GetMonitorName(monitor);
        double ui_scale = 1.0f;
        int value;

        if (g_variant_lookup(dict, monitor_name.c_str(), "i", &value) && value > 0)
          ui_scale = static_cast<double>(value)/8.0f;

        if (app_target_monitor.Str() == monitor_name)
          app_target_scale = ui_scale;

        dpi = DEFAULT_DPI * ui_scale;
        min_scale = std::min(min_scale, ui_scale);
        max_scale = std::max(max_scale, ui_scale);
      }

      if (em_converters_[monitor]->SetDPI(dpi))
        any_changed = true;
    }

    if (app_target_scale == 0)
      app_target_scale = (g_settings_get_boolean(ui_settings_, APP_USE_MAX_SCALE.c_str())) ? max_scale : min_scale;

    UpdateAppsScaling(app_target_scale);

    if (any_changed)
      parent_->dpi_changed.emit();
  }
static void
set_lock_value_for_combo (GtkComboBox *combo_box, CcScreenPanel *self)
{
  GtkTreeIter iter;
  GtkTreeModel *model;
  guint value;
  gint value_tmp, value_prev;
  gboolean ret;
  guint i;

  /* get entry */
  model = gtk_combo_box_get_model (combo_box);
  ret = gtk_tree_model_get_iter_first (model, &iter);
  if (!ret)
    return;

  value_prev = 0;
  i = 0;

  /* try to make the UI match the lock setting */
  g_settings_get (self->priv->lock_settings, "lock-delay", "u", &value);

  do
    {
      gtk_tree_model_get (model, &iter,
                          1, &value_tmp,
                          -1);
      if (value == value_tmp ||
          (value_tmp > value_prev && value < value_tmp))
        {
          gtk_combo_box_set_active_iter (combo_box, &iter);
          return;
        }
      value_prev = value_tmp;
      i++;
    } while (gtk_tree_model_iter_next (model, &iter));

  /* If we didn't find the setting in the list */
  gtk_combo_box_set_active (combo_box, i - 1);
}
예제 #14
0
/**
 * gva_main_get_last_selected_match:
 * @column_name: return location for the column name
 * @search_text: return location for the search text
 *
 * Returns the most recently selected match in a search completion list
 * from either the current or previous session of <emphasis>GNOME Video
 * Arcade</emphasis>.  If the completion feature was not used in the
 * most recent search, @column_name and @search_text are set to %NULL
 * and the function returns %FALSE.
 *
 * Returns: %TRUE if match values were successfully retrieved from
 *          GSettings, %FALSE otherwise
 **/
gboolean
gva_main_get_last_selected_match (gchar **column_name,
                                  gchar **search_text)
{
        GSettings *settings;

        g_return_val_if_fail (column_name != NULL, FALSE);
        g_return_val_if_fail (search_text != NULL, FALSE);

        settings = gva_get_settings ();

        *column_name = *search_text = NULL;

        g_settings_get (
                settings, GVA_SETTING_SELECTED_MATCH,
                "(ss)", column_name, search_text);

        /* The value may be unset.  Treat it as a failure. */
        if (*column_name == NULL || *search_text == NULL)
                goto fail;

        g_strstrip (*column_name);
        g_strstrip (*search_text);

        /* Both strings must be non-empty. */
        if (**column_name == '\0' || **search_text == '\0')
                goto fail;

        return TRUE;

fail:
        g_free (*column_name);
        g_free (*search_text);

        *column_name = *search_text = NULL;

        return FALSE;
}
예제 #15
0
static void
fr_file_selector_dialog_get_default_size (FrFileSelectorDialog *self,
					  int                  *default_width,
					  int                  *default_height)
{
	int width, height;

	g_settings_get (self->priv->settings, PREF_FILE_SELECTOR_WINDOW_SIZE, "(ii)", &width, &height);
	if ((width > 0) && (height > 0)) {
		*default_width = width;
		*default_height = height;
		return;
	}

	find_good_window_size_from_style (GTK_WIDGET (self), default_width, default_height);

	if ((self->priv->extra_widget != NULL) && gtk_widget_get_visible (self->priv->extra_widget)) {
		GtkRequisition req;

		gtk_widget_get_preferred_size (GET_WIDGET ("extra_widget_container"),  &req, NULL);
		*default_height += gtk_box_get_spacing (GTK_BOX (GET_WIDGET ("content"))) + req.height;
	}
}
예제 #16
0
static void
terminal_app_encoding_list_notify_cb (GSettings   *settings,
                                      const char  *key,
                                      TerminalApp *app)
{
  gs_strfreev char **encodings = NULL;
  int i;
  TerminalEncoding *encoding;

  app->encodings_locked = !g_settings_is_writable (settings, key);

  /* Mark all as non-active, then re-enable the active ones */
  g_hash_table_foreach (app->encodings, (GHFunc) encoding_mark_active, GUINT_TO_POINTER (FALSE));

  /* First add the locale's charset */
  encoding = g_hash_table_lookup (app->encodings, "current");
  g_assert (encoding);
  if (terminal_encoding_is_valid (encoding))
    encoding->is_active = TRUE;

  /* Also always make UTF-8 available */
  encoding = g_hash_table_lookup (app->encodings, "UTF-8");
  g_assert (encoding);
  if (terminal_encoding_is_valid (encoding))
    encoding->is_active = TRUE;

  g_settings_get (settings, key, "^as", &encodings);
  for (i = 0; encodings[i] != NULL; ++i) {
      encoding = terminal_app_ensure_encoding (app, encodings[i]);
      if (!terminal_encoding_is_valid (encoding))
        continue;

      encoding->is_active = TRUE;
    }

  g_signal_emit (app, signals[ENCODING_LIST_CHANGED], 0);
}
예제 #17
0
/* Create the preferences dialog. */
void
preferences_create(ChimaraGlk *glk)
{
	/* Initialize the tree of style names */
	GtkTreeStore *style_list = GTK_TREE_STORE( load_object("style-list") );
	GtkTreeIter buffer, grid, buffer_child, grid_child;

	gtk_tree_store_append(style_list, &buffer, NULL);
	gtk_tree_store_append(style_list, &grid, NULL);
	gtk_tree_store_set(style_list, &buffer, 0, "Text buffer", -1);
	gtk_tree_store_set(style_list, &grid, 0, "Text grid", -1);

	unsigned i, num_tags;
	const char * const *tag_names = chimara_glk_get_tag_names(glk, &num_tags);
	for(i=0; i<num_tags; i++) {
		gtk_tree_store_append(style_list, &buffer_child, &buffer);
		gtk_tree_store_append(style_list, &grid_child, &grid);
		gtk_tree_store_set(style_list, &buffer_child, 0, tag_names[i], -1);
		gtk_tree_store_set(style_list, &grid_child, 0, tag_names[i], -1);
	}

	/* Set selection mode to single select */
	GtkTreeView *view = GTK_TREE_VIEW( load_object("style-treeview") );
	GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
	gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
	g_signal_connect(selection, "changed", G_CALLBACK(style_tree_select_callback), glk);

	/* Bind the preferences to the entries in the preferences file */
	extern GSettings *prefs_settings;
	GObject *flep = G_OBJECT( load_object("flep") );
	g_settings_bind(prefs_settings, "flep", flep, "active", G_SETTINGS_BIND_DEFAULT);
	GtkFileChooser *blorb_chooser = GTK_FILE_CHOOSER( load_object("blorb_file_chooser") );
	GtkFileChooser *css_chooser = GTK_FILE_CHOOSER( load_object("css-filechooser") );
	char *filename;
	g_settings_get(prefs_settings, "resource-path", "ms", &filename);
	if(filename) {
		gtk_file_chooser_set_filename(blorb_chooser, filename);
		g_free(filename);
	}
	g_settings_get(prefs_settings, "css-file", "ms", &filename);
	if(filename) {
		if(!chimara_glk_set_css_from_file(glk, filename, NULL)) {
			/* If the setting didn't point to a CSS file, fail silently and
			 null the setting */
			g_settings_set(prefs_settings, "css-file", "ms", NULL);
		} else {
			gtk_file_chooser_set_filename(css_chooser, filename);
		}
		g_free(filename);
	}

	/* Populate the list of available interpreters */
	GtkListStore *interp_list = GTK_LIST_STORE( load_object("available_interpreters") );
	unsigned int count;
	GtkTreeIter tree_iter;
	for(count = 0; count < CHIMARA_IF_NUM_INTERPRETERS; count++) {
		gtk_list_store_append(interp_list, &tree_iter);
		gtk_list_store_set(interp_list, &tree_iter,
			0, interpreter_to_display_string(count),
			-1);
	}

	/* Get the list of preferred interpreters from the preferences */
	GVariantIter *iter;
	char *format, *plugin;
	g_settings_get(prefs_settings, "preferred-interpreters", "a{ss}", &iter);
	while(g_variant_iter_loop(iter, "{ss}", &format, &plugin)) {
		ChimaraIFFormat format_num = parse_format(format);
		if(format_num == CHIMARA_IF_FORMAT_NONE)
			continue;
		ChimaraIFInterpreter interp_num = parse_interpreter(plugin);
		if(interp_num == CHIMARA_IF_INTERPRETER_NONE)
			continue;
		chimara_if_set_preferred_interpreter(CHIMARA_IF(glk), format_num, interp_num);
	}
	g_variant_iter_free(iter);

	/* Display it all in the list */
	preferred_list = GTK_LIST_STORE( load_object("interpreters") );
	for(count = 0; count < CHIMARA_IF_NUM_FORMATS; count++) {
		gtk_list_store_append(preferred_list, &tree_iter);
		gtk_list_store_set(preferred_list, &tree_iter,
			0, format_to_display_string(count),
			1, interpreter_to_display_string(chimara_if_get_preferred_interpreter(CHIMARA_IF(glk), count)),
			-1);
	}
}
예제 #18
0
void
create_main_window (GsmApplication *app)
{
    GtkApplicationWindow *main_window;
    GtkStack *stack;
    GtkMenuButton *process_menu_button;
    GMenuModel *process_menu_model;
    GdkDisplay *display;
    GdkMonitor *monitor;
    GdkRectangle monitor_geometry;
    const char* session;

    int width, height, xpos, ypos;

    GtkBuilder *builder = gtk_builder_new();
    gtk_builder_add_from_resource (builder, "/org/gnome/gnome-system-monitor/data/interface.ui", NULL);
    gtk_builder_add_from_resource (builder, "/org/gnome/gnome-system-monitor/data/menus.ui", NULL);

    main_window = GTK_APPLICATION_WINDOW (gtk_builder_get_object (builder, "main_window"));
    gtk_window_set_application (GTK_WINDOW (main_window), app->gobj());
    gtk_widget_set_name (GTK_WIDGET (main_window), "gnome-system-monitor");
    app->main_window = main_window;

    session = g_getenv ("XDG_CURRENT_DESKTOP");
    if (session && !strstr (session, "GNOME")){
        GtkBox *mainbox;
        GtkHeaderBar *headerbar;

        mainbox = GTK_BOX (gtk_builder_get_object (builder, "main_box"));
        headerbar = GTK_HEADER_BAR (gtk_builder_get_object (builder, "header_bar"));
        gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (headerbar)), "titlebar");
        gtk_window_set_titlebar (GTK_WINDOW (main_window), NULL);
        gtk_header_bar_set_show_close_button (headerbar, FALSE);
        gtk_box_pack_start (mainbox, GTK_WIDGET (headerbar), FALSE, FALSE, 0);
    }

    g_settings_get (app->settings->gobj(), GSM_SETTING_WINDOW_STATE, "(iiii)",
                    &width, &height, &xpos, &ypos);
    
    display = gdk_display_get_default ();
    monitor = gdk_display_get_monitor_at_point (display, xpos, ypos);
    if (monitor == NULL) {
        monitor = gdk_display_get_monitor (display, 0);
    }
    gdk_monitor_get_geometry (monitor, &monitor_geometry);

    width = CLAMP (width, 50, monitor_geometry.width);
    height = CLAMP (height, 50, monitor_geometry.height);
    xpos = CLAMP (xpos, 0, monitor_geometry.width - width);
    ypos = CLAMP (ypos, 0, monitor_geometry.height - height);

    gtk_window_set_default_size (GTK_WINDOW (main_window), width, height);
    gtk_window_move (GTK_WINDOW (main_window), xpos, ypos);
    if (app->settings->get_boolean (GSM_SETTING_MAXIMIZED))
        gtk_window_maximize (GTK_WINDOW (main_window));

    app->process_menu_button = process_menu_button = GTK_MENU_BUTTON (gtk_builder_get_object (builder, "process_menu_button"));
    process_menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "process-window-menu"));
    gtk_menu_button_set_menu_model (process_menu_button, process_menu_model);

    app->end_process_button = GTK_BUTTON (gtk_builder_get_object (builder, "end_process_button"));

    app->search_button = GTK_BUTTON (gtk_builder_get_object (builder, "search_button"));

    GActionEntry win_action_entries[] = {
        { "about", on_activate_about, NULL, NULL, NULL },
        { "search", on_activate_search, "b", "false", NULL },
        { "send-signal-stop", on_activate_send_signal, "i", NULL, NULL },
        { "send-signal-cont", on_activate_send_signal, "i", NULL, NULL },
        { "send-signal-end", on_activate_send_signal, "i", NULL, NULL },
        { "send-signal-kill", on_activate_send_signal, "i", NULL, NULL },
        { "priority", on_activate_priority, "i", "@i 0", change_priority_state },
        { "memory-maps", on_activate_memory_maps, NULL, NULL, NULL },
        { "open-files", on_activate_open_files, NULL, NULL, NULL },
        { "process-properties", on_activate_process_properties, NULL, NULL, NULL },
        { "refresh", on_activate_refresh, NULL, NULL, NULL },
        { "show-page", on_activate_radio, "s", "'resources'", change_show_page_state },
        { "show-whose-processes", on_activate_radio, "s", "'all'", change_show_processes_state },
        { "show-dependencies", on_activate_toggle, NULL, "false", change_show_dependencies_state }
    };

    g_action_map_add_action_entries (G_ACTION_MAP (main_window),
                                     win_action_entries,
                                     G_N_ELEMENTS (win_action_entries),
                                     app);

    GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET (main_window));
    GdkVisual* visual = gdk_screen_get_rgba_visual(screen);

    /* use visual, if available */
    if (visual)
        gtk_widget_set_visual(GTK_WIDGET (main_window), visual);

    /* create the main stack */
    app->stack = stack = GTK_STACK (gtk_builder_get_object (builder, "stack"));

    create_proc_view(app, builder);

    create_sys_view (app, builder);
    
    create_disk_view (app, builder);

    g_settings_bind (app->settings->gobj (), GSM_SETTING_CURRENT_TAB, stack, "visible-child-name", G_SETTINGS_BIND_DEFAULT);

    g_signal_connect (G_OBJECT (stack), "notify::visible-child",
                      G_CALLBACK (cb_change_current_page), app);

    g_signal_connect (G_OBJECT (main_window), "delete_event",
                      G_CALLBACK (cb_main_window_delete),
                      app);
    g_signal_connect (G_OBJECT (main_window), "window-state-event",
                      G_CALLBACK (cb_main_window_state_changed),
                      app);

    GAction *action;
    action = g_action_map_lookup_action (G_ACTION_MAP (main_window),
                                         "show-dependencies");
    g_action_change_state (action,
                           g_settings_get_value (app->settings->gobj (), GSM_SETTING_SHOW_DEPENDENCIES));


    action = g_action_map_lookup_action (G_ACTION_MAP (main_window),
                                         "show-whose-processes");
    g_action_change_state (action,
                           g_settings_get_value (app->settings->gobj (), GSM_SETTING_SHOW_WHOSE_PROCESSES));

    gtk_widget_show (GTK_WIDGET (main_window));
    
    update_page_activities (app);

    g_object_unref (G_OBJECT (builder));
}
예제 #19
0
void
modeline_parser_apply_modeline (GtkSourceView *view)
{
	ModelineOptions options;
	GtkTextBuffer *buffer;
	GtkTextIter iter, liter;
	gint line_count;
	GSettings *settings;

	options.language_id = NULL;
	options.set = MODELINE_SET_NONE;

	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
	gtk_text_buffer_get_start_iter (buffer, &iter);

	line_count = gtk_text_buffer_get_line_count (buffer);

	/* Parse the modelines on the 10 first lines... */
	while ((gtk_text_iter_get_line (&iter) < 10) &&
	       !gtk_text_iter_is_end (&iter))
	{
		gchar *line;

		liter = iter;
		gtk_text_iter_forward_to_line_end (&iter);
		line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE);

		parse_modeline (line,
				1 + gtk_text_iter_get_line (&iter),
				line_count,
				&options);

		gtk_text_iter_forward_line (&iter);

		g_free (line);
	}

	/* ...and on the 10 last ones (modelines are not allowed in between) */
	if (!gtk_text_iter_is_end (&iter))
	{
		gint cur_line;
		guint remaining_lines;

		/* we are on the 11th line (count from 0) */
		cur_line = gtk_text_iter_get_line (&iter);
		/* g_assert (10 == cur_line); */

		remaining_lines = line_count - cur_line - 1;

		if (remaining_lines > 10)
		{
			gtk_text_buffer_get_end_iter (buffer, &iter);
			gtk_text_iter_backward_lines (&iter, 9);
		}
	}

	while (!gtk_text_iter_is_end (&iter))
	{
		gchar *line;

		liter = iter;
		gtk_text_iter_forward_to_line_end (&iter);
		line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE);

		parse_modeline (line,
				1 + gtk_text_iter_get_line (&iter),
				line_count,
				&options);

		gtk_text_iter_forward_line (&iter);

		g_free (line);
	}

	/* Try to set language */
	if (has_option (&options, MODELINE_SET_LANGUAGE) && options.language_id)
	{
		if (g_ascii_strcasecmp (options.language_id, "text") == 0)
		{
			gedit_document_set_language (GEDIT_DOCUMENT (buffer),
			                             NULL);
		}
		else
		{
		        GtkSourceLanguageManager *manager;
		        GtkSourceLanguage *language;

		        manager = gedit_get_language_manager ();

			language = gtk_source_language_manager_get_language
					(manager, options.language_id);
			if (language != NULL)
			{
				gedit_document_set_language (GEDIT_DOCUMENT (buffer),
				                             language);
			}
			else
			{
				gedit_debug_message (DEBUG_PLUGINS,
						     "Unknown language `%s'",
						     options.language_id);
			}
		}
	}

	ModelineOptions *previous = g_object_get_data (G_OBJECT (buffer), 
	                                               MODELINE_OPTIONS_DATA_KEY);

	settings = g_settings_new ("org.gnome.gedit.preferences.editor");

	/* Apply the options we got from modelines and restore defaults if
	   we set them before */
	if (has_option (&options, MODELINE_SET_INSERT_SPACES))
	{
		gtk_source_view_set_insert_spaces_instead_of_tabs
							(view, options.insert_spaces);
	}
	else if (check_previous (view, previous, MODELINE_SET_INSERT_SPACES))
	{
		gboolean insert_spaces;
		
		insert_spaces = g_settings_get_boolean (settings, GEDIT_SETTINGS_INSERT_SPACES);
	
		gtk_source_view_set_insert_spaces_instead_of_tabs (view, insert_spaces);
	}
	
	if (has_option (&options, MODELINE_SET_TAB_WIDTH))
	{
		gtk_source_view_set_tab_width (view, options.tab_width);
	}
	else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH))
	{
		guint tab_width;
		
		g_settings_get (settings, GEDIT_SETTINGS_TABS_SIZE, "u", &tab_width);
	
		gtk_source_view_set_tab_width (view, tab_width);
	}
	
	if (has_option (&options, MODELINE_SET_INDENT_WIDTH))
	{
		gtk_source_view_set_indent_width (view, options.indent_width);
	}
	else if (check_previous (view, previous, MODELINE_SET_INDENT_WIDTH))
	{
		gtk_source_view_set_indent_width (view, -1);
	}
	
	if (has_option (&options, MODELINE_SET_WRAP_MODE))
	{
		gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), options.wrap_mode);
	}
	else if (check_previous (view, previous, MODELINE_SET_WRAP_MODE))
	{
		GtkWrapMode mode;
		
		mode = g_settings_get_enum (settings,
					    GEDIT_SETTINGS_WRAP_MODE);
		gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), mode);
	}
	
	if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION))
	{
		gtk_source_view_set_right_margin_position (view, options.right_margin_position);
	}
	else if (check_previous (view, previous, MODELINE_SET_RIGHT_MARGIN_POSITION))
	{
		guint right_margin_pos;
		
		g_settings_get (settings, GEDIT_SETTINGS_RIGHT_MARGIN_POSITION, "u",
				&right_margin_pos);
		gtk_source_view_set_right_margin_position (view, 
		                                           right_margin_pos);
	}
	
	if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN))
	{
		gtk_source_view_set_show_right_margin (view, options.display_right_margin);
	}
	else if (check_previous (view, previous, MODELINE_SET_SHOW_RIGHT_MARGIN))
	{
		gboolean display_right_margin;
		
		display_right_margin = g_settings_get_boolean (settings,
							       GEDIT_SETTINGS_DISPLAY_RIGHT_MARGIN);
		gtk_source_view_set_show_right_margin (view, display_right_margin);
	}
	
	if (previous)
	{
		g_free (previous->language_id);
		*previous = options;
		previous->language_id = g_strdup (options.language_id);
	}
	else
	{
		previous = g_slice_new (ModelineOptions);
		*previous = options;
		previous->language_id = g_strdup (options.language_id);
		
		g_object_set_data_full (G_OBJECT (buffer), 
		                        MODELINE_OPTIONS_DATA_KEY, 
		                        previous,
		                        (GDestroyNotify)free_modeline_options);
	}

	g_object_unref (settings);
	g_free (options.language_id);
}