summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deadbeef.h1
-rw-r--r--playlist.c57
-rw-r--r--playlist.h3
-rw-r--r--plugins.c1
-rw-r--r--plugins/gtkui/ddbtabstrip.c33
5 files changed, 77 insertions, 18 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 0739c169..e6fad0f4 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -289,6 +289,7 @@ typedef struct {
int (*plt_get_curr) (void);
int (*plt_get_title) (int plt, char *buffer, int bufsize);
int (*plt_set_title) (int plt, const char *title);
+ void (*plt_move) (int from, int before);
// playlist control
void (*pl_lock) (void);
void (*pl_unlock) (void);
diff --git a/playlist.c b/playlist.c
index 30a9df82..75597389 100644
--- a/playlist.c
+++ b/playlist.c
@@ -361,6 +361,59 @@ plt_free (void) {
}
void
+plt_move (int from, int before) {
+ if (from == before) {
+ return;
+ }
+ int i;
+ PLT_LOCK;
+ playlist_t *p = playlists_head;
+
+ playlist_t *pfrom = NULL;
+ playlist_t *prev = NULL;
+ playlist_t *ins = NULL;
+
+ for (i = 0; p && i <= from; i++) {
+ if (i == from) {
+ pfrom = p;
+ if (prev) {
+ prev->next = p->next;
+ }
+ else {
+ playlists_head = p->next;
+ }
+ break;
+ }
+ prev = p;
+ p = p->next;
+ }
+// if (before > from) {
+// before--;
+// }
+
+ if (before == 0) {
+ pfrom->next = playlists_head;
+ playlists_head = pfrom;
+ }
+ else {
+ p = playlists_head;
+ for (i = 0; p && i < before; i++) {
+ if (i == before-1) {
+ playlist_t *next = p->next;
+ p->next = pfrom;
+ pfrom->next = next;
+ break;
+ }
+ prev = p;
+ p = p->next;
+ }
+ }
+
+ PLT_UNLOCK;
+ plt_gen_conf ();
+}
+
+void
pl_clear (void) {
LOCK;
while (playlist->head[PL_MAIN]) {
@@ -1426,10 +1479,10 @@ pl_delete_selected (void) {
}
}
if (playlist->current_row[PL_MAIN] >= playlist->count[PL_MAIN]) {
- playlist->current_row[PL_MAIN] == playlist->count[PL_MAIN] - 1;
+ playlist->current_row[PL_MAIN] = playlist->count[PL_MAIN] - 1;
}
if (playlist->current_row[PL_SEARCH] >= playlist->count[PL_SEARCH]) {
- playlist->current_row[PL_SEARCH] == playlist->count[PL_SEARCH] - 1;
+ playlist->current_row[PL_SEARCH] = playlist->count[PL_SEARCH] - 1;
}
GLOBAL_UNLOCK;
return ret;
diff --git a/playlist.h b/playlist.h
index 7783f2e8..c14cd643 100644
--- a/playlist.h
+++ b/playlist.h
@@ -121,6 +121,9 @@ plt_get_title (int plt, char *buffer, int bufsize);
int
plt_set_title (int plt, const char *title);
+void
+plt_move (int from, int before);
+
// playlist access functions
void
pl_clear (void);
diff --git a/plugins.c b/plugins.c
index 568857f3..89a0ce69 100644
--- a/plugins.c
+++ b/plugins.c
@@ -112,6 +112,7 @@ static DB_functions_t deadbeef_api = {
.plt_get_curr = plt_get_curr,
.plt_get_title = plt_get_title,
.plt_set_title = plt_set_title,
+ .plt_move = plt_move,
// playlist access
.pl_lock = pl_lock,
.pl_unlock = pl_unlock,
diff --git a/plugins/gtkui/ddbtabstrip.c b/plugins/gtkui/ddbtabstrip.c
index ec279d1c..7be9b6f8 100644
--- a/plugins/gtkui/ddbtabstrip.c
+++ b/plugins/gtkui/ddbtabstrip.c
@@ -320,7 +320,7 @@ tabstrip_draw (GtkWidget *widget) {
gtk_paint_box (widget->style, backbuf, GTK_STATE_ACTIVE, GTK_SHADOW_ETCHED_IN, NULL, widget, "button", x, 0, w, h);
}
#endif
- x += ts->movepos;
+ x = ts->movepos;
if (x >= widget->allocation.width) {
break;
}
@@ -378,7 +378,14 @@ on_tabstrip_button_press_event (GtkWidget *widget,
if (tab_clicked != -1) {
deadbeef->plt_set_curr (tab_clicked);
}
- ts->dragpt[0] = event->x - ts->hscrollpos;
+
+ int x = -ts->hscrollpos + tabs_left_margin;
+ int idx;
+ for (idx = 0; idx < tab_clicked; idx++) {
+ int width = ddb_tabstrip_get_tab_width (ts, idx);
+ x += width - tab_overlap_size;
+ }
+ ts->dragpt[0] = event->x - x;
ts->dragpt[1] = event->y;
ts->prepare = 1;
ts->dragging = tab_clicked;
@@ -425,7 +432,6 @@ on_tabstrip_expose_event (GtkWidget *widget,
return FALSE;
}
-
gboolean
on_tabstrip_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
@@ -445,28 +451,23 @@ on_tabstrip_motion_notify_event (GtkWidget *widget,
if (!ts->prepare && ts->dragging >= 0) {
// gdk_window_set_cursor (widget->window, cursor_drag);
ts->movepos = ev_x - ts->dragpt[0];
- int drag_width = ddb_tabstrip_get_tab_width (ts, ts->dragging);
// find closest tab to the left
+ int idx;
+ int x = -ts->hscrollpos + tabs_left_margin;
int inspos = -1;
- int x = 0;
- int idx = 0;
- int x1 = -1, x2 = -1;
int cnt = deadbeef->plt_get_count ();
- for (idx = 0; idx < ts->dragging; idx++) {
+ for (idx = 0; idx < cnt; idx++) {
int width = ddb_tabstrip_get_tab_width (ts, idx);
- if (x < ts->movepos && x + width > ts->movepos) {
+ if (idx != ts->dragging && x <= ts->movepos && x + width/2 - tab_overlap_size > ts->movepos) {
inspos = idx;
- x1 = x;
- }
- else if (idx == ts->dragging) {
- x2 = x;
+ break;
}
- x += drag_width;
+ x += width - tab_overlap_size;
}
if (inspos >= 0 && inspos != ts->dragging) {
- //ddb_tabstrip_tab_move (ps, c, inspos);
- //ts->dragging = inspos;
+ deadbeef->plt_move (ts->dragging, inspos);
+ ts->dragging = inspos;
}
tabstrip_draw (widget);
}