Ejemplo n.º 1
0
/*
 * get clipboard content - partialy inspired by Downloader for X
 */
gboolean
my_get_xselection(GtkWidget *window, GdkEvent *event)
{
	GdkAtom		atom;
	gint		format;
	size_t		length;
	gchar		*content = NULL;

	/* previous clipboard content */
	static size_t	old_content_len = 0;
	static gchar	*old_content = "";


	begin_func("my_get_xselection");

	gtk_clipboard_request_text(gtk_clipboard_get(clipboard),
			my_get_selection_text, NULL);

	return_val(TRUE);

	length = (size_t) gdk_selection_property_get(gtk_widget_get_window(window),
			(guchar **) &content, &atom, &format);

	if (length > 0) {
		if ((length != old_content_len ||
				memcmp(content, old_content, length) != 0) &&
		    !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore))) {
			/* new data in clipboard */
			/* store new content for future comparation */
			if (old_content_len > 0)
				g_free(old_content);
			old_content = content;
			old_content_len = length;

			/* process item */
			/* process_item(content, length, 0, TRUE); */
		} else {
			/* no new data */
			g_free(content);
		}

		/* when clipboard is locked, set selection owener to myself */
		    if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore)) ||
			gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_lock))) {
			if (gtk_selection_owner_set(dock_app,
						clipboard,
						GDK_CURRENT_TIME) == 0)
				selected = NULL;
		}

	}

	return_val(TRUE);
}
Ejemplo n.º 2
0
/*
 * handles request for selection from other apps
 */
gboolean
selection_handle(GtkWidget *widget,
		GtkSelectionData *selection_data,
		guint info,
		guint time_stamp,
		gpointer data)
{
	static gchar	*converted = NULL;

	begin_func("selection_handle");

	if (converted != NULL) {
		g_free(converted);
	}

	if (selected) {
		converted = from_utf8(selected->content);
		gtk_selection_data_set(selection_data,
				GDK_SELECTION_TYPE_STRING,
				8,
				(guchar *) converted,
				strlen(converted));
	} else {
		gtk_selection_data_set(selection_data,
				GDK_SELECTION_TYPE_STRING,
				8,
				(guchar *)"",
				0);
	}

	return_val(TRUE);
}
Ejemplo n.º 3
0
int
foo_val (void)
{
  ENTER ("foo_val");
  foo_void ();
  return_val (1);
}
std::string Functions::toString(int value, std::string::size_type length)
{
	char buffer[32];
	sprintf(buffer, "%d", value);
	std::string return_val(buffer);
	return_val = std::string(max(0, length-return_val.length()), '0') + return_val;
	return return_val;
}
Ejemplo n.º 5
0
/*
 * parse key string
 */
int
hotkey_parse(char *hotkey, guint *key, guint *mask)
{
	char	c;
	char	*tmp = g_new0(char, strlen(hotkey));
	int	i, idx = 0;

	begin_func("hotkey_parse");

	*mask = 0;

	for (i = 0; i < strlen(hotkey); i++) {
		c = hotkey[i];
		if (isalpha(c)) {
			tmp[idx++] = c;
			tmp[idx] = '\0';
		} else if (c == '+' || c == '-') {
			idx = 0;
			if (strcasecmp(tmp, "control") == 0 ||
					strcasecmp(tmp, "ctrl") == 0)
				*mask |= ControlMask;
			else if (strcasecmp(tmp, "alt") == 0)
				*mask |= Mod1Mask;
			else if (strcasecmp(tmp, "shift") == 0)
				*mask |= ShiftMask;
			else {
				fprintf(stderr, "Invalid key modifier: %s\n",
						tmp);
				g_free(tmp);
				return_val(-1);
			}
		}
	}

	if ((*key = gdk_keyval_from_name(tmp)) == GDK_KEY_VoidSymbol) {
		g_free(tmp);
		return_val(-1);
	}

	g_free(tmp);
	return_val(0);
}
Ejemplo n.º 6
0
/*
 * clipboard conversion - inspired by Downloader for X too :)
 */
gboolean
time_conv_select()
{
	begin_func("time_conv_select");

	gtk_selection_convert(main_window,
			clipboard,
			GDK_TARGET_STRING,
			GDK_CURRENT_TIME);
	return_val(TRUE);
}
Ejemplo n.º 7
0
/*
 * clipboard conversion - inspired by Downloader for X too :)
 */
gboolean
time_conv_select()
{
	begin_func("time_conv_select");

	gtk_selection_convert(main_window,
			GDK_SELECTION_PRIMARY,
			GDK_TARGET_STRING,
			GDK_CURRENT_TIME);
	return_val(TRUE);
}
Ejemplo n.º 8
0
/*
 * get clipboard content - partialy inspired by Downloader for X
 */
gboolean
my_get_xselection(GtkWidget *window, GdkEvent *event)
{

	begin_func("my_get_xselection");

	gtk_clipboard_request_text(gtk_clipboard_get(clipboard),
			my_get_selection_text, NULL);

	return_val(TRUE);
}
Ejemplo n.º 9
0
/*
 * filter grabbed hotkeys
 */
GdkFilterReturn
global_keys_filter(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
{
	XEvent	*xevent = (XEvent *)gdk_xevent;

	begin_func("global_keys_filter");

	if (xevent->type == KeyPress) {
		if (xevent->xkey.keycode ==
				XKeysymToKeycode(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), menukey) &&
				xevent->xkey.state & menukey_mask) {
			/* popup history menu */
			gtk_menu_popup(GTK_MENU(menu_hist),
					NULL, NULL,
					NULL, NULL,
					0,
					GDK_CURRENT_TIME);
			return_val(GDK_FILTER_REMOVE);
		} else if (xevent->xkey.keycode ==
				XKeysymToKeycode(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), prev_item_key)
				&& xevent->xkey.state & prev_item_mask) {
			/* switch first two history items */
			GList *second;
			if (history_items == NULL) {
				return_val(GDK_FILTER_REMOVE);
			}
			second = g_list_first(history_items)->next;
			if (second == NULL) {
				return_val(GDK_FILTER_REMOVE);
			}

			move_item_to_begin((HISTORY_ITEM *) second->data);

			return_val(GDK_FILTER_REMOVE);
		} else if (xevent->xkey.keycode ==
				XKeysymToKeycode(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), exec_item_key) &&
				xevent->xkey.state & exec_item_mask) {
			/* exec command on current item */
			if (exec_hotkey) {
				HISTORY_ITEM *hist_item;
				hist_item = (HISTORY_ITEM *) g_list_first(history_items)->data;
				exec_item(hist_item->content, NULL);
			}
			return_val(GDK_FILTER_REMOVE);
		}
	}

	return_val(GDK_FILTER_CONTINUE);
}