Boutified that patch of yesterday
Philip Van Hoof <[email protected]>
| Newsgroups | gmane.comp.multimedia.xmms.devel |
|---|---|
| Organization | Cronos |
| Message-ID | <1076081080.6621.76.camel@localhost> |
Hi there again, fellow geeks!! Well, this patch is just ... much better and much more like the other code of xmms. It still breaks older drag and drop functionality, and indeed that sucks (moving the items up or down using your mouse). I have not yet figured out how to fix that. But using this patch, both drag and drop functionalities are now in the playlist_list.c in stead of the playlistwin.c. I am guessing that the dragging and dropping of playlist items belongs to the playlist_list.c widget, not to the playlistwin window (widget). Btw. This does NOT mean that I like the way you guys crippled the Gtk+ widgets. I mean, wtf? Why create a new "Widget"-type and when the parent gets a click, make that parent loop all it's custom Widgets and pass the click through if it's in the region of that custom Widget. Damn.. thats like: lets just rewrite X! Wow and stuff .. Oh well, heck .. this patch makes stuff like all other xmms-code is. Bleh! Maybe some dude should think about dragging and dropping issues in the Gtk2 version of xmms (AND make it compatible with the specifications of freedesktop.org). Since this patch modifies multiple files, I hope I included everything. If not then please to contact me. -- Philip Van Hoof, Software Developer @ Cronos home: me at freax dot org work: Philip dot VanHoof at cronos dot be http://www.freax.be, http://www.freax.eu.org _______________________________________________ xmms-devel mailing list [email protected] http://lists.xmms.org/mailman/listinfo/xmms-devel
xmms_dnd_patch.diff
(text/x-patch, 11 KB)
Index: dnd.h
===================================================================
RCS file: /cvs/xmms/xmms/dnd.h,v
retrieving revision 1.2
diff -u -r1.2 dnd.h
--- dnd.h 6 Jun 2000 13:59:21 -0000 1.2
+++ dnd.h 6 Feb 2004 15:04:48 -0000
@@ -23,9 +23,20 @@
XMMS_DROP_URLENCODED
};
+enum {
+ XMMS_DRAG_PLAINTEXT,
+ XMMS_DRAG_URLENCODED
+};
+
/* Drag data format listing for gtk_drag_dest_set() */
extern const GtkTargetEntry _xmms_drop_types[];
+extern const GtkTargetEntry _xmms_drag_types[];
#define xmms_drag_dest_set(widget) gtk_drag_dest_set(widget, \
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, \
_xmms_drop_types, 3, GDK_ACTION_COPY | GDK_ACTION_MOVE)
+
+#define xmms_drag_source_set(widget) gtk_drag_source_set (widget ,\
+ GDK_BUTTON1_MASK, \
+ _xmms_drag_types, 2, \
+ GDK_ACTION_MOVE | GDK_ACTION_COPY)
Index: main.c
===================================================================
RCS file: /cvs/xmms/xmms/main.c,v
retrieving revision 1.148
diff -u -r1.148 main.c
--- main.c 16 Jan 2004 22:15:38 -0000 1.148
+++ main.c 6 Feb 2004 15:04:53 -0000
@@ -106,6 +106,12 @@
{"STRING", 0, XMMS_DROP_STRING}
};
+const GtkTargetEntry _xmms_drag_types[] =
+{
+ {"text/plain", 0, XMMS_DROP_PLAINTEXT},
+ {"text/uri-list", 0, XMMS_DROP_URLENCODED},
+};
+
void mainwin_options_menu_callback(gpointer cb_data, guint action, GtkWidget * w);
void mainwin_volume_motioncb(gint pos);
static void set_timer_mode_menu_cb(TimerMode mode);
Index: playlist_list.c
===================================================================
RCS file: /cvs/xmms/xmms/playlist_list.c,v
retrieving revision 1.24
diff -u -r1.24 playlist_list.c
--- playlist_list.c 8 Jun 2003 21:52:02 -0000 1.24
+++ playlist_list.c 6 Feb 2004 15:04:53 -0000
@@ -24,6 +24,7 @@
#endif
#include <X11/Xatom.h>
+GList *filestodrag = NULL;
static GdkFont *playlist_list_font = NULL;
static int playlist_list_auto_drag_down_func(gpointer data)
@@ -501,6 +502,100 @@
PL_UNLOCK();
}
+
+GString*
+make_url_list (GList *list,
+ int target)
+{
+ GList *scan;
+ GString *result;
+ const gchar *url_sep="";
+ const gchar *prefix="";
+
+ if (list == NULL)
+ return NULL;
+
+ switch (target) {
+ case XMMS_DRAG_PLAINTEXT:
+ case XMMS_DRAG_URLENCODED:
+ prefix = "file://";
+ url_sep = "\r\n";
+ break;
+ }
+
+ result = g_string_new (NULL);
+ for (scan = list; scan; scan = scan->next) {
+ g_string_append (result, prefix);
+ g_string_append (result, scan->data);
+ g_string_append (result, url_sep);
+ }
+
+ return result;
+}
+
+void
+playlist_list_drag_begin_cb (GtkWidget *widget, GdkDragContext *context, gpointer extra_data)
+{
+ GList *list;
+
+ PL_LOCK();
+ if ((list = get_playlist()) == NULL)
+ {
+ PL_UNLOCK();
+ return;
+ }
+ if (((PlaylistEntry *) list->data)->selected)
+ {
+ /* We are at the top */
+ PL_UNLOCK();
+ return;
+ }
+ while (list)
+ {
+ if (((PlaylistEntry *) list->data)->selected)
+ {
+ filestodrag = g_list_append (filestodrag, ((PlaylistEntry *) list->data)->filename);
+ }
+ list = g_list_next(list);
+ }
+ PL_UNLOCK();
+}
+
+void
+playlist_list_drag_end_cb (GtkWidget *widget, GdkDragContext *context, gpointer extra_data)
+{
+ if (filestodrag != NULL)
+ g_list_free (filestodrag);
+ filestodrag = NULL;
+}
+
+void
+playlist_list_drag_data_get_cb(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, gpointer extra_data)
+{
+ gint target_id=0;
+ gchar *target = gdk_atom_name (selection_data->target);
+ GString *url_list;
+
+ if (strcmp (target, "text/uri-list") == 0)
+ target_id = XMMS_DRAG_URLENCODED;
+ else if (strcmp (target, "text/plain") == 0)
+ target_id = XMMS_DRAG_PLAINTEXT;
+ g_free (target);
+
+ url_list = make_url_list (filestodrag, target_id);
+
+ if (url_list == NULL)
+ return;
+
+ gtk_selection_data_set (selection_data,
+ selection_data->target,
+ 8,
+ url_list->str,
+ url_list->len);
+
+ g_string_free (url_list, TRUE);
+}
+
PlayList_List *create_playlist_list(GList ** wlist, GdkPixmap * parent, GdkGC * gc, gint x, gint y, gint w, gint h)
{
PlayList_List *pl;
@@ -516,11 +611,15 @@
pl->pl_widget.button_press_cb = GTK_SIGNAL_FUNC(playlist_list_button_press_cb);
pl->pl_widget.button_release_cb = GTK_SIGNAL_FUNC(playlist_list_button_release_cb);
pl->pl_widget.motion_cb = GTK_SIGNAL_FUNC(playlist_list_motion_cb);
+ pl->pl_widget.drag_begin_cb = GTK_SIGNAL_FUNC(playlist_list_drag_begin_cb);
+ pl->pl_widget.drag_end_cb = GTK_SIGNAL_FUNC(playlist_list_drag_end_cb);
+ pl->pl_widget.drag_data_get_cb = GTK_SIGNAL_FUNC(playlist_list_drag_data_get_cb);
pl->pl_widget.draw = playlist_list_draw;
pl->pl_prev_selected = -1;
pl->pl_prev_min = -1;
pl->pl_prev_max = -1;
add_widget(wlist, pl);
+
return pl;
}
Index: playlistwin.c
===================================================================
RCS file: /cvs/xmms/xmms/playlistwin.c,v
retrieving revision 1.88
diff -u -r1.88 playlistwin.c
--- playlistwin.c 28 Jan 2004 00:11:25 -0000 1.88
+++ playlistwin.c 6 Feb 2004 15:04:56 -0000
@@ -1912,6 +1912,21 @@
playlist_add_url_string(selection_data->data);
}
+static void playlistwin_drag_begin (GtkWidget *widget, GdkDragContext *context, gpointer extra_data)
+{
+ handle_drag_begin_cb (playlistwin_wlist, widget, context);
+}
+
+static void playlistwin_drag_end (GtkWidget *widget, GdkDragContext *context, gpointer extra_data)
+{
+ handle_drag_end_cb (playlistwin_wlist, widget, context);
+}
+
+static void playlistwin_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, gpointer extra_data)
+{
+ handle_drag_data_get_cb(playlistwin_wlist, widget, context, selection_data, info, time);
+}
+
static void playlistwin_create_gtk(void)
{
playlistwin = gtk_window_new(GTK_WINDOW_DIALOG);
@@ -1942,9 +1957,15 @@
gtk_signal_connect(GTK_OBJECT(playlistwin), "configure_event", GTK_SIGNAL_FUNC(playlistwin_configure), NULL);
gtk_signal_connect(GTK_OBJECT(playlistwin), "client_event", GTK_SIGNAL_FUNC(playlistwin_client_event), NULL);
xmms_drag_dest_set(playlistwin);
+ xmms_drag_source_set(playlistwin);
gtk_signal_connect(GTK_OBJECT(playlistwin), "drag-data-received", GTK_SIGNAL_FUNC(playlistwin_drag_data_received), NULL);
gtk_signal_connect(GTK_OBJECT(playlistwin), "key-press-event", GTK_SIGNAL_FUNC(playlistwin_keypress), NULL);
gtk_signal_connect(GTK_OBJECT(playlistwin), "selection_received", GTK_SIGNAL_FUNC(selection_received), NULL);
+
+ gtk_signal_connect(GTK_OBJECT(playlistwin), "drag_begin", GTK_SIGNAL_FUNC(playlistwin_drag_begin), NULL);
+ gtk_signal_connect(GTK_OBJECT(playlistwin), "drag_end", GTK_SIGNAL_FUNC(playlistwin_drag_end), NULL);
+ gtk_signal_connect(GTK_OBJECT(playlistwin), "drag_data_get", GTK_SIGNAL_FUNC(playlistwin_drag_data_get), NULL);
+
if (!cfg.show_wm_decorations)
gdk_window_set_decorations(playlistwin->window, 0);
Index: widget.c
===================================================================
RCS file: /cvs/xmms/xmms/widget.c,v
retrieving revision 1.2
diff -u -r1.2 widget.c
--- widget.c 16 Feb 2000 21:06:00 -0000 1.2
+++ widget.c 6 Feb 2004 15:04:57 -0000
@@ -105,6 +105,45 @@
}
}
+void handle_drag_begin_cb(GList * wlist, GtkWidget * widget, GdkDragContext *context)
+{
+ GList *wl;
+
+ wl = wlist;
+ while (wl)
+ {
+ if (((Widget *) wl->data)->drag_begin_cb)
+ ((Widget *) wl->data)->drag_begin_cb(widget, context, (Widget *) wl->data);
+ wl = wl->next;
+ }
+}
+
+void handle_drag_end_cb(GList * wlist, GtkWidget * widget, GdkDragContext *context)
+{
+ GList *wl;
+
+ wl = wlist;
+ while (wl)
+ {
+ if (((Widget *) wl->data)->drag_end_cb)
+ ((Widget *) wl->data)->drag_end_cb(widget, context, (Widget *) wl->data);
+ wl = wl->next;
+ }
+}
+
+void handle_drag_data_get_cb(GList * wlist, GtkWidget * widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time)
+{
+ GList *wl;
+
+ wl = wlist;
+ while (wl)
+ {
+ if (((Widget *) wl->data)->drag_data_get_cb)
+ ((Widget *) wl->data)->drag_data_get_cb(widget, context, selection_data, info, time, (Widget *) wl->data);
+ wl = wl->next;
+ }
+}
+
void draw_widget_list(GList * wlist, gboolean * redraw, gboolean force)
{
/*
Index: widget.h
===================================================================
RCS file: /cvs/xmms/xmms/widget.h,v
retrieving revision 1.2
diff -u -r1.2 widget.h
--- widget.h 16 Feb 2000 21:06:00 -0000 1.2
+++ widget.h 6 Feb 2004 15:04:57 -0000
@@ -26,6 +26,9 @@
void (*button_press_cb) (GtkWidget *, GdkEventButton *, gpointer);
void (*button_release_cb) (GtkWidget *, GdkEventButton *, gpointer);
void (*motion_cb) (GtkWidget *, GdkEventMotion *, gpointer);
+ void (*drag_begin_cb) (GtkWidget *, GdkDragContext *, gpointer);
+ void (*drag_end_cb) (GtkWidget *, GdkDragContext *, gpointer);
+ void (*drag_data_get_cb) (GtkWidget *, GdkDragContext *, GtkSelectionData *, guint, guint, gpointer);
void (*draw) (struct _Widget *);
gboolean redraw;
pthread_mutex_t mutex;
@@ -42,6 +45,9 @@
void handle_press_cb(GList * wlist, GtkWidget * widget, GdkEventButton * event);
void handle_release_cb(GList * wlist, GtkWidget * widget, GdkEventButton * event);
void handle_motion_cb(GList * wlist, GtkWidget * widget, GdkEventMotion * event);
+void handle_drag_begin_cb(GList * wlist, GtkWidget * widget, GdkDragContext *context);
+void handle_drag_end_cb(GList * wlist, GtkWidget * widget, GdkDragContext *context);
+void handle_drag_data_get_cb(GList * wlist, GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time);
void draw_widget_list(GList * wlist, gboolean * redraw, gboolean force);
void widget_list_change_pixmap(GList * wlist, GdkPixmap * pixmap);
void clear_widget_list_redraw(GList * wlist);