#include "player.h"
#include "Fsb.h"
+#include "Sidebar.h"
static MainWindow *main_window;
static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *args, int nargs);
static void FileOpenCB(Widget w, void *udata, void *cdata);
+static void FileQuitCB(Widget w, void *udata, void *cdata);
+static void PlayRepeatCB(Widget w, void *udata, void *cdata);
+static void PlayRepeatListCB(Widget w, void *udata, void *cdata);
+static void PlayAutoPlayCB(Widget w, void *udata, void *cdata);
static void ViewFullscreenCB(Widget w, void *udata, void *cdata);
+static void ViewSidebarCB(Widget w, void *udata, void *cdata);
static void WindowRealized(MainWindow *win);
+static int blank_cursor_init = 0;
+static Pixmap blank_cursor_pixmap;
+static Cursor blank_cursor;
+
+static void init_blank_cursor(Widget w) {
+ char data = 0;
+
+ XColor c;
+
+ blank_cursor_pixmap = XCreateBitmapFromData(XtDisplay(w), XtWindow(w), &data, 1, 1);
+ if(!blank_cursor_pixmap) return;
+
+ blank_cursor = XCreatePixmapCursor(XtDisplay(w), blank_cursor_pixmap, blank_cursor_pixmap, &c, &c, 0, 0);
+
+ XFreePixmap(XtDisplay(w), blank_cursor_pixmap);
+ blank_cursor_init = 1;
+}
+
static void window_close_handler(Widget window, void *udata, void *cdata) {
- WindowClosePlayer(main_window);
- ApplicationExit();
+ FileQuitCB(window, NULL, NULL);
}
static unsigned int keycodeF;
static int main_window_is_realized = 0;
-static void resizeEH(Widget widget, XtPointer data, XEvent *event, Boolean *dispatch) {
+static void resizeEH(Widget widget, XtPointer data, XEvent *event, Boolean *dispatch) {
if(!main_window_is_realized) {
if(XtIsRealized(widget)) {
main_window_is_realized = 1;
PlayerOpenFile(win);
CleanOpenFileArg();
}
+
+ if(!blank_cursor_init) {
+ init_blank_cursor(win->player_widget);
+ }
}
static void playerWidgetInputCB(Widget widget, XtPointer u, XtPointer c) {
}
}
-static void playerEH(Widget widget, XtPointer data, XEvent *event, Boolean *dispatch) {
- MainWindow *win = data;
- if(!win->player || win->player->window == 0) return;
-
- /*
- if(event->type == EnterNotify) {
- printf("enter: grab pointer\n");
-
- XtGrabPointer(
+static void windowGrabButton(MainWindow *win) {
+ //printf("grab\n");
+ XtGrabButton(
win->player_widget,
+ AnyButton,
+ AnyModifier,
True,
ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask,
GrabModeAsync,
GrabModeAsync,
None,
- None,
- CurrentTime);
-
+ None);
+ win->buttongrab = True;
+}
+
+static void playerEH(Widget widget, XtPointer data, XEvent *event, Boolean *dispatch) {
+ MainWindow *win = data;
+ int etype = event->type;
+
+ ///*
+ if(etype == EnterNotify) {
+ //printf("enter\n");
+ windowGrabButton(win);
return;
}
- if(event->type == LeaveNotify) {
- printf("leave\n");
- XtUngrabPointer(win->player_widget, CurrentTime);
+ if(etype == LeaveNotify) {
+ //printf("leave\n");
+ //XtUngrabButton(win->player_widget, AnyButton, AnyModifier);
+ //win->buttongrab = False;
return;
}
- if(event->type == MotionNotify) {
- static int testv = 0;
- printf("test %d\n", testv++);
+ int pass = 0;
+ if(etype == ButtonPress || etype == ButtonRelease || etype == KeyPress || etype == KeyRelease) {
+ //printf("button press\n");
+ pass = 1;
}
- */
- if(event->type == KeyPress || event->type == KeyRelease) {
+ if(!win->player || win->player->window == 0) return;
+
+ WindowHandlePlayerEvent(win, event);
+
+ if(pass) {
// redirect key events to the player window
+ //printf("redirect\n");
event->xkey.window = win->player->window;
XSendEvent(
XtDisplay(win->player_widget),
}
}
+#define IGNORE_MOTION_THRESHOLD_MS 1000
+#define MOTION_POS_THRESHOLD_PIX 5
+
+#define DOUBLE_CLICK_TIME_MS 500
+
+void WindowHandlePlayerEvent(MainWindow *win, XEvent *event) {
+ // event handler for intercepted player mouse events
+ // win->player is not NULL
+
+ int etype = event->type;
+
+ if(etype == MotionNotify) {
+ Time cur_motion_time = event->xmotion.time;
+ if(win->player) {
+ win->motion_playback_time = win->player->playback_time;
+ }
+
+ int x = event->xmotion.x_root;
+ int y = event->xmotion.y_root;
+ if(win->cursorhidden && cur_motion_time - win->player_event_time < IGNORE_MOTION_THRESHOLD_MS) {
+ int diff_x = abs(x - win->mouse_x);
+ int diff_y = abs(y - win->mouse_y);
+ if(diff_x > MOTION_POS_THRESHOLD_PIX || diff_y > MOTION_POS_THRESHOLD_PIX) {
+ WindowShowPlayerCursor(win);
+ }
+ } else {
+ win->mouse_x = x;
+ win->mouse_y = y;
+ }
+ win->player_event_time = cur_motion_time;
+ win->motion_playback_time = win->player->playback_time;
+
+
+
+ if(win->pwbuttonpressed) {
+ Display *dp = XtDisplay(win->window);
+
+ XtUngrabPointer(win->player_widget, CurrentTime);
+
+ XEvent xev;
+ memset(&xev, 0, sizeof(xev));
+ xev.type = ClientMessage;
+ xev.xclient.message_type = XInternAtom(dp, "_NET_WM_MOVERESIZE", False);
+ xev.xclient.window = XtWindow(win->window);
+ xev.xclient.format = 32;
+ xev.xclient.data.l[0] = x;
+ xev.xclient.data.l[1] = y;
+ xev.xclient.data.l[2] = 8; // _NET_WM_MOVERESIZE_MOVE
+ xev.xclient.data.l[3] = 1; // button1
+ xev.xclient.data.l[4] = 1; // source indication
+
+ XSendEvent(dp, DefaultRootWindow(dp), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
+
+ win->pwbuttonpressed = FALSE;
+ }
+ } else if(etype == ButtonPress) {
+ Time t = event->xbutton.time;
+ if(t - win->button_press_time < DOUBLE_CLICK_TIME_MS) {
+ // double click
+ WindowFullscreen(main_window, !win->fullscreen);
+ win->button_press_time = 0;
+ } else {
+ win->button_press_time = t;
+ }
+ win->pwbuttonpressed = 1;
+ } else if(etype == ButtonRelease) {
+ win->player_event_time = event->xbutton.time;
+ win->pwbuttonpressed = FALSE;
+ }
+}
+
MainWindow* WindowCreate(Display *display) {
Arg args[32];
int n;
-
+
MainWindow *window = malloc(sizeof(MainWindow));
memset(window, 0, sizeof(MainWindow));
main_window = window;
WindowCreateMenu(window, container, args, n);
n = 0;
+ XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
+ XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
+ XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
+ XtSetArg(args[n], XmNtopWidget, window->menubar); n++;
+ XtSetArg(args[n], XmNwidth, 300); n++;
+ window->sidebar = CreateSidebar(container, "sidebar", args, n);
+ //XtManageChild(window->sidebar);
+
+ n = 0;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
+ XtSetArg(args[n], XmNrightWidget, window->sidebar); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNtopWidget, window->menubar); n++;
EnterWindowMask | KeyPressMask | KeyReleaseMask |
LeaveWindowMask, FALSE, playerEH, window);
-
+
// get F keycode
keycodeF = XKeysymToKeycode(XtDisplay(window->window), XStringToKeysym("F"));
return menuItem;
}
+/*
+ * Creates a XmToggleButton menu item
+ */
+static Widget createToggleMenuItem(
+ Widget menu,
+ char *name,
+ char *label,
+ char mnemonic,
+ Boolean defaultValue,
+ const char *accelerator,
+ char *accelerator_text,
+ XtCallbackProc callback,
+ void *cbData)
+{
+ Arg args[16];
+ int n = 0;
+
+ XmString s1 = XmStringCreateSimple(label);
+ XtSetArg(args[n], XmNlabelString, s1); n++;
+ XtSetArg(args[n], XmNmnemonic, mnemonic); n++;
+ XtSetArg(args[n], XmNset, defaultValue); n++;
+ XmString at = NULL;
+ if(accelerator && accelerator_text) {
+ at = XmStringCreateSimple(accelerator_text);
+ XtSetArg(args[n], XmNaccelerator, accelerator); n++;
+ XtSetArg(args[n], XmNacceleratorText, at); n++;
+ }
+
+ Widget menuItem = XmCreateToggleButtonGadget(menu, name, args, n);
+ XtManageChild(menuItem);
+ XmStringFree(s1);
+ if(at) XmStringFree(at);
+
+ if(callback) {
+ XtAddCallback(menuItem, XmNvalueChangedCallback, (XtCallbackProc)callback, cbData);
+ }
+
+ return menuItem;
+}
+
static void WindowCreateMenu(MainWindow *win, Widget parent, Arg *mbargs, int nmbargs) {
Widget menubar = XmCreateMenuBar(parent, "menubar", mbargs, nmbargs);
XtManageChild(menubar);
// menus
XmString s = XmStringCreateSimple("File");
- Widget fileMenuItem = XtVaCreateManagedWidget(
+ XtVaCreateManagedWidget(
"menuitem",
xmCascadeButtonWidgetClass,
menubar,
Widget fileMenu = XmVaCreateSimplePulldownMenu(menubar, "menu", 0, NULL, NULL);
s = XmStringCreateSimple("Playback");
- Widget playMenuItem = XtVaCreateManagedWidget(
+ XtVaCreateManagedWidget(
"menuitem",
xmCascadeButtonWidgetClass,
menubar,
// file menu
createMenuItem(fileMenu, "fileOpen", "Open...", 'O', "Ctrl<Key>O", "Ctrl+O", FileOpenCB, NULL);
+ createMenuItem(fileMenu, "fileQuit", "Exit", 'E', "Ctrl<Key>Q", "Ctrl+Q", FileQuitCB, NULL);
+
+ // play menu
+ win->playRepeatTrackButton = createToggleMenuItem(playMenu, "playRepeatTrack", "Repeat", 'R', False, NULL, NULL, PlayRepeatCB, win);
+ win->playRepeatListButton = createToggleMenuItem(playMenu, "playRepeatList", "Repeat List", 'L', False, NULL, NULL, PlayRepeatListCB, win);
+ win->playAutoPlayButton = createToggleMenuItem(playMenu, "playAutoNext", "Autoplay Folder", 'A', False, NULL, NULL, PlayAutoPlayCB, win);
+ XtVaSetValues(win->playRepeatTrackButton, XmNindicatorType, XmONE_OF_MANY, NULL);
+ XtVaSetValues(win->playRepeatListButton, XmNindicatorType, XmONE_OF_MANY, NULL);
+ XtVaSetValues(win->playAutoPlayButton, XmNindicatorType, XmONE_OF_MANY, NULL);
// view menu
createMenuItem(viewMenu, "viewFullscreen", "Fullscreen", 'F', "<Key>F", "F", ViewFullscreenCB, NULL);
+ win->viewSidebarButton = createToggleMenuItem(viewMenu, "viewSidebar", "View Sidebar", 'S', False, NULL, NULL, ViewSidebarCB, win);
}
void go_fullscreen(Display *dsp, Window win)
XtManageChild(dialog);
}
+static void FileQuitCB(Widget w, void *udata, void *cdata) {
+ WindowClosePlayer(main_window);
+ ApplicationExit();
+}
+
+static void PlayRepeatCB(Widget w, void *udata, void *cdata) {
+ MainWindow *win = udata;
+ win->repeatTrack = XmToggleButtonGadgetGetState(w);
+ win->repeatList = 0;
+ win->autoplayFolder = 0;
+ XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL);
+ XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL);
+}
+
+static void PlayRepeatListCB(Widget w, void *udata, void *cdata) {
+ MainWindow *win = udata;
+ win->repeatList = XmToggleButtonGadgetGetState(w);
+ win->repeatTrack = 0;
+ win->autoplayFolder = 0;
+ XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL);
+ XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL);
+}
+
+static void PlayAutoPlayCB(Widget w, void *udata, void *cdata) {
+ MainWindow *win = udata;
+ win->autoplayFolder = XmToggleButtonGadgetGetState(w);
+ win->repeatTrack = 0;
+ win->repeatList = 0;
+ XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL);
+ XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL);
+}
+
static void ViewFullscreenCB(Widget w, void *udata, void *cdata) {
if(main_window->fullscreen) {
WindowFullscreen(main_window, FALSE);
} else {
WindowFullscreen(main_window, TRUE);
+ }
+}
+
+static void ViewSidebarCB(Widget w, void *udata, void *cdata) {
+ MainWindow *win = udata;
+ XmToggleButtonCallbackStruct *cb = cdata;
+ if(cb->set) {
+ WindowShowSidebar(win);
+ } else {
+ WindowHideSidebar(win);
}
-
}
void WindowAdjustAspectRatio(MainWindow *win) {
if(!win->player) return;
if(!win->player->isactive || win->player->width <= 0 || win->player->height <= 0) return;
-
+
// we have a running player width video
// adjust window aspect ratio (the window aspect ratio is different from
// the video, because of window decoration, menubar and other extra controls)
PlayerDestroy(win->player);
}
win->player = NULL;
+ WindowShowPlayerCursor(win);
}
+
+void WindowHidePlayerCursor(MainWindow *win) {
+ if(!win->cursorhidden && win->player && win->player->window != 0) {
+ XDefineCursor(XtDisplay(win->player_widget), XtWindow(win->player_widget), blank_cursor);
+ win->cursorhidden = True;
+ XFlush(XtDisplay(win->player_widget));
+ }
+}
+
+void WindowShowPlayerCursor(MainWindow *win) {
+ if(win->cursorhidden && win->player && win->player->window != 0) {
+ XDefineCursor(XtDisplay(win->player_widget), XtWindow(win->player_widget), None);
+ XFlush(XtDisplay(win->player_widget));
+ }
+ win->cursorhidden = False;
+}
+
+void WindowHideSidebar(MainWindow *win) {
+ XtUnmanageChild(win->sidebar);
+ XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_FORM, NULL);
+}
+
+void WindowShowSidebar(MainWindow *win) {
+ XtManageChild(win->sidebar);
+ XtVaSetValues(win->player_widget, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, win->sidebar, NULL);
+}
+