~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to libvo/x11_common.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "libavutil/common.h"
29
29
#include "x11_common.h"
30
30
 
31
 
#ifdef X11_FULLSCREEN
32
 
 
33
31
#include <string.h>
34
32
#include <unistd.h>
35
33
#include <assert.h>
89
87
static int orig_layer = 0;
90
88
static int old_gravity = NorthWestGravity;
91
89
 
92
 
int stop_xscreensaver = 0;
 
90
int stop_xscreensaver = 1;
93
91
 
94
92
static int dpms_disabled = 0;
95
93
 
141
139
/*
142
140
 * Sends the EWMH fullscreen state event.
143
141
 *
 
142
 * win:    id of the window to which the event shall be sent
144
143
 * action: could be one of _NET_WM_STATE_REMOVE -- remove state
145
144
 *                         _NET_WM_STATE_ADD    -- add state
146
145
 *                         _NET_WM_STATE_TOGGLE -- toggle
147
146
 */
148
 
void vo_x11_ewmh_fullscreen(int action)
 
147
void vo_x11_ewmh_fullscreen(Window win, int action)
149
148
{
150
149
    assert(action == _NET_WM_STATE_REMOVE ||
151
150
           action == _NET_WM_STATE_ADD || action == _NET_WM_STATE_TOGGLE);
159
158
        xev.xclient.serial = 0;
160
159
        xev.xclient.send_event = True;
161
160
        xev.xclient.message_type = XA_NET_WM_STATE;
162
 
        xev.xclient.window = vo_window;
 
161
        xev.xclient.window = win;
163
162
        xev.xclient.format = 32;
164
163
        xev.xclient.data.l[0] = action;
165
164
        xev.xclient.data.l[1] = XA_NET_WM_STATE_FULLSCREEN;
177
176
    }
178
177
}
179
178
 
180
 
void vo_hidecursor(Display * disp, Window win)
 
179
static void vo_hidecursor(Display * disp, Window win)
181
180
{
182
181
    Cursor no_ptr;
183
182
    Pixmap bm_no;
185
184
    Colormap colormap;
186
185
    static char bm_no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
187
186
 
188
 
    if (WinID == 0)
189
 
        return;                 // do not hide if playing on the root window
 
187
    if (WinID >= 0)
 
188
        return;        // do not hide if attached to an existing window
190
189
 
191
190
    colormap = DefaultColormap(disp, DefaultScreen(disp));
192
191
    if ( !XAllocNamedColor(disp, colormap, "black", &black, &dummy) )
202
201
    XFreeColors(disp,colormap,&black.pixel,1,0);
203
202
}
204
203
 
205
 
void vo_showcursor(Display * disp, Window win)
 
204
static void vo_showcursor(Display * disp, Window win)
206
205
{
207
 
    if (WinID == 0)
208
 
        return;
 
206
    if (WinID >= 0)
 
207
        return;        // do not show if attached to an existing window
209
208
    XDefineCursor(disp, win, 0);
210
209
}
211
210
 
551
550
#include "osdep/keycodes.h"
552
551
#include "wskeys.h"
553
552
 
554
 
#ifdef XF86XK_AudioPause
555
553
static const struct mp_keymap keysym_map[] = {
 
554
#ifdef XF86XK_AudioPause
556
555
    {XF86XK_MenuKB, KEY_MENU},
557
556
    {XF86XK_AudioPlay, KEY_PLAY}, {XF86XK_AudioPause, KEY_PAUSE}, {XF86XK_AudioStop, KEY_STOP},
558
557
    {XF86XK_AudioPrev, KEY_PREV}, {XF86XK_AudioNext, KEY_NEXT},
559
558
    {XF86XK_AudioMute, KEY_MUTE}, {XF86XK_AudioLowerVolume, KEY_VOLUME_DOWN}, {XF86XK_AudioRaiseVolume, KEY_VOLUME_UP},
 
559
#endif
560
560
    {0, 0}
561
561
};
562
562
 
563
 
static void vo_x11_putkey_ext(int keysym)
 
563
static int vo_x11_putkey_ext(int keysym)
564
564
{
565
565
    int mpkey = lookup_keymap_table(keysym_map, keysym);
566
566
    if (mpkey)
567
567
        mplayer_put_key(mpkey);
 
568
    return mpkey != 0;
568
569
}
569
 
#endif
570
570
 
571
571
static const struct mp_keymap keymap[] = {
572
572
    // special keys
729
729
{
730
730
    XClassHint wmClass;
731
731
    pid_t pid = getpid();
 
732
    long prop = pid & 0x7FFFFFFF;
732
733
 
733
734
    wmClass.res_name = vo_winname ? vo_winname : name;
734
735
    wmClass.res_class = "MPlayer";
735
736
    XSetClassHint(display, window, &wmClass);
 
737
 
 
738
    /* PID sizes other than 32-bit are not handled by the EWMH spec */
 
739
    if ((pid_t)prop != pid)
 
740
        return;
 
741
 
736
742
    XChangeProperty(display, window, XA_NET_WM_PID, XA_CARDINAL, 32,
737
 
                    PropModeReplace, (unsigned char *) &pid, 1);
 
743
                    PropModeReplace, (unsigned char *)&prop, 1);
738
744
}
739
745
 
740
746
Window vo_window = None;
806
812
    char buf[100];
807
813
    KeySym keySym;
808
814
    static XComposeStatus stat;
 
815
    static int ctrl_state;
809
816
 
810
817
    if (vo_mouse_autohide && mouse_waiting_hide &&
811
818
                                 (GetTimerMS() - mouse_timer >= 1000)) {
821
828
#ifdef CONFIG_GUI
822
829
        if (use_gui)
823
830
        {
824
 
            guiGetEvent(0, (char *) &Event);
 
831
            gui(GUI_HANDLE_X_EVENT, &Event);
825
832
            if (vo_window != Event.xany.window)
826
833
                continue;
827
834
        }
838
845
                ret |= check_resize();
839
846
                break;
840
847
            case KeyPress:
 
848
            case KeyRelease:
841
849
                {
842
850
                    int key;
843
851
 
847
855
 
848
856
                    XLookupString(&Event.xkey, buf, sizeof(buf), &keySym,
849
857
                                  &stat);
850
 
#ifdef XF86XK_AudioPause
851
 
                    vo_x11_putkey_ext(keySym);
852
 
#endif
853
858
                    key =
854
859
                        ((keySym & 0xff00) !=
855
860
                         0 ? ((keySym & 0x00ff) + 256) : (keySym));
856
 
                    vo_x11_putkey(key);
 
861
                    if (key == wsLeftCtrl || key == wsRightCtrl) {
 
862
                        ctrl_state = Event.type == KeyPress;
 
863
                        mplayer_put_key(KEY_CTRL |
 
864
                            (ctrl_state ? MP_KEY_DOWN : 0));
 
865
                    } else if (Event.type == KeyRelease) {
 
866
                        break;
 
867
                    }
 
868
                    // Attempt to fix if somehow our state got out of
 
869
                    // sync with reality.
 
870
                    // This usually happens when a shortcut involving CTRL
 
871
                    // was used to switch to a different window/workspace.
 
872
                    if (ctrl_state != !!(Event.xkey.state & 4)) {
 
873
                        ctrl_state = !!(Event.xkey.state & 4);
 
874
                        mplayer_put_key(KEY_CTRL |
 
875
                            (ctrl_state ? MP_KEY_DOWN : 0));
 
876
                    }
 
877
                    if (!vo_x11_putkey_ext(keySym)) {
 
878
                        vo_x11_putkey(key);
 
879
                    }
857
880
                    ret |= VO_EVENT_KEYPRESS;
858
881
                }
859
882
                break;
1068
1091
                             Colormap col_map,
1069
1092
                             const char *classname, const char *title)
1070
1093
{
 
1094
  if (vo_wintitle)
 
1095
    title = vo_wintitle;
1071
1096
  if (WinID >= 0) {
1072
1097
    vo_fs = flags & VOFLAG_FULLSCREEN;
1073
1098
    vo_window = WinID ? (Window)WinID : mRootWin;
1090
1115
      // if it relies on events being forwarded to the parent of WinID.
1091
1116
      // It also is consistent with the w32_common.c code.
1092
1117
      vo_x11_selectinput_witherr(mDisplay, vo_window,
1093
 
          StructureNotifyMask | KeyPressMask | PointerMotionMask |
 
1118
          StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
1094
1119
          ButtonPressMask | ButtonReleaseMask | ExposureMask);
1095
1120
 
1096
1121
    vo_x11_update_geometry();
1106
1131
  }
1107
1132
  if (flags & VOFLAG_HIDDEN)
1108
1133
    goto final;
 
1134
  XStoreName(mDisplay, vo_window, title);
1109
1135
  if (window_state & VOFLAG_HIDDEN) {
1110
1136
    XSizeHints hint;
1111
1137
    XEvent xev;
1112
1138
    window_state &= ~VOFLAG_HIDDEN;
1113
1139
    vo_x11_classhint(mDisplay, vo_window, classname);
1114
 
    XStoreName(mDisplay, vo_window, title);
1115
1140
    vo_hidecursor(mDisplay, vo_window);
1116
1141
    XSelectInput(mDisplay, vo_window, StructureNotifyMask);
1117
1142
    hint.x = x; hint.y = y;
1131
1156
    XSelectInput(mDisplay, vo_window, NoEventMask);
1132
1157
    XSync(mDisplay, False);
1133
1158
    vo_x11_selectinput_witherr(mDisplay, vo_window,
1134
 
          StructureNotifyMask | KeyPressMask | PointerMotionMask |
 
1159
          StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
1135
1160
          ButtonPressMask | ButtonReleaseMask | ExposureMask);
1136
1161
  }
1137
1162
  if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop);
1340
1365
    if (w <= INT_MAX && h <= INT_MAX) { vo_dwidth = w; vo_dheight = h; }
1341
1366
    XTranslateCoordinates(mDisplay, vo_window, mRootWin, 0, 0, &vo_dx, &vo_dy,
1342
1367
                          &dummy_win);
1343
 
    if (vo_wintitle)
1344
 
        XStoreName(mDisplay, vo_window, vo_wintitle);
1345
1368
 
1346
1369
    return depth <= INT_MAX ? depth : 0;
1347
1370
}
1363
1386
 
1364
1387
    if (vo_fs)
1365
1388
    {
1366
 
        vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE);   // removes fullscreen state if wm supports EWMH
 
1389
        vo_x11_ewmh_fullscreen(vo_window, _NET_WM_STATE_REMOVE);   // removes fullscreen state if wm supports EWMH
1367
1390
        vo_fs = VO_FALSE;
1368
1391
    } else
1369
1392
    {
1370
1393
        // win->fs
1371
 
        vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD);      // sends fullscreen state to be added if wm supports EWMH
 
1394
        vo_x11_ewmh_fullscreen(vo_window, _NET_WM_STATE_ADD);      // sends fullscreen state to be added if wm supports EWMH
1372
1395
 
1373
1396
        vo_fs = VO_TRUE;
1374
1397
        if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // not needed with EWMH fs
1516
1539
{
1517
1540
    int nothing;
1518
1541
 
1519
 
    if (screensaver_off)
 
1542
    if (!stop_xscreensaver || screensaver_off)
1520
1543
        return;
1521
1544
    screensaver_off = 1;
1522
1545
    if (xss_suspend(True))
1681
1704
}
1682
1705
#endif
1683
1706
 
1684
 
#endif                          /* X11_FULLSCREEN */
1685
 
 
1686
1707
 
1687
1708
/*
1688
1709
 * Scan the available visuals on this Display/Screen.  Try to find