diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-02-11 13:30:04 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-02-11 13:30:04 +0400 |
commit | fb01dcea5ff167b838e25f234029f93b690954dc (patch) | |
tree | 00f37a6385bf7aab2d342faa7fa95cc476b2f73b /intern/ghost | |
parent | 53bce285ab42641959ce11095732d34a8e893f88 (diff) |
move atoms into their own struct and make all names match the original atom names, there were too many and mixed in with the classes namespace.
Diffstat (limited to 'intern/ghost')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemX11.cpp | 111 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemX11.h | 64 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_WindowX11.cpp | 44 |
3 files changed, 111 insertions, 108 deletions
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index f8c7bf45ffc..48fb8375303 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -109,36 +109,37 @@ GHOST_SystemX11( m_xim = NULL; #endif - m_delete_window_atom - = XInternAtom(m_display, "WM_DELETE_WINDOW", True); - - m_wm_protocols = XInternAtom(m_display, "WM_PROTOCOLS", False); - m_wm_take_focus = XInternAtom(m_display, "WM_TAKE_FOCUS", False); - m_wm_state = XInternAtom(m_display, "WM_STATE", False); - m_wm_change_state = XInternAtom(m_display, "WM_CHANGE_STATE", False); - m_net_state = XInternAtom(m_display, "_NET_WM_STATE", False); - m_net_max_horz = XInternAtom(m_display, - "_NET_WM_STATE_MAXIMIZED_HORZ", False); - m_net_max_vert = XInternAtom(m_display, - "_NET_WM_STATE_MAXIMIZED_VERT", False); - m_net_fullscreen = XInternAtom(m_display, - "_NET_WM_STATE_FULLSCREEN", False); - m_motif = XInternAtom(m_display, "_MOTIF_WM_HINTS", False); - m_targets = XInternAtom(m_display, "TARGETS", False); - m_string = XInternAtom(m_display, "STRING", False); - m_compound_text = XInternAtom(m_display, "COMPOUND_TEXT", False); - m_text = XInternAtom(m_display, "TEXT", False); - m_clipboard = XInternAtom(m_display, "CLIPBOARD", False); - m_primary = XInternAtom(m_display, "PRIMARY", False); - m_xclip_out = XInternAtom(m_display, "XCLIP_OUT", False); - m_incr = XInternAtom(m_display, "INCR", False); - m_utf8_string = XInternAtom(m_display, "UTF8_STRING", False); +#define GHOST_INTERN_ATOM_IF_EXISTS(atom) { m_atom.atom = XInternAtom(m_display, #atom , True); } (void)0 +#define GHOST_INTERN_ATOM(atom) { m_atom.atom = XInternAtom(m_display, #atom , False); } (void)0 + + GHOST_INTERN_ATOM_IF_EXISTS(WM_DELETE_WINDOW); + GHOST_INTERN_ATOM(WM_PROTOCOLS); + GHOST_INTERN_ATOM(WM_TAKE_FOCUS); + GHOST_INTERN_ATOM(WM_STATE); + GHOST_INTERN_ATOM(WM_CHANGE_STATE); + GHOST_INTERN_ATOM(_NET_WM_STATE); + GHOST_INTERN_ATOM(_NET_WM_STATE_MAXIMIZED_HORZ); + GHOST_INTERN_ATOM(_NET_WM_STATE_MAXIMIZED_VERT); + + GHOST_INTERN_ATOM(_NET_WM_STATE_FULLSCREEN); + GHOST_INTERN_ATOM(_MOTIF_WM_HINTS); + GHOST_INTERN_ATOM(TARGETS); + GHOST_INTERN_ATOM(STRING); + GHOST_INTERN_ATOM(COMPOUND_TEXT); + GHOST_INTERN_ATOM(TEXT); + GHOST_INTERN_ATOM(CLIPBOARD); + GHOST_INTERN_ATOM(PRIMARY); + GHOST_INTERN_ATOM(XCLIP_OUT); + GHOST_INTERN_ATOM(INCR); + GHOST_INTERN_ATOM(UTF8_STRING); #ifdef WITH_X11_XINPUT - m_xi_tablet = XInternAtom(m_display, XI_TABLET, False); + m_atom.TABLET = XInternAtom(m_display, XI_TABLET, False); #endif - m_last_warp = 0; +#undef GHOST_INTERN_ATOM_IF_EXISTS +#undef GHOST_INTERN_ATOM + m_last_warp = 0; /* compute the initial time */ timeval tv; @@ -963,7 +964,7 @@ GHOST_SystemX11::processEvent(XEvent *xe) { XClientMessageEvent & xcme = xe->xclient; - if (((Atom)xcme.data.l[0]) == m_delete_window_atom) { + if (((Atom)xcme.data.l[0]) == m_atom.WM_DELETE_WINDOW) { g_event = new GHOST_Event( getMilliSeconds(), @@ -971,7 +972,7 @@ GHOST_SystemX11::processEvent(XEvent *xe) window ); } - else if (((Atom)xcme.data.l[0]) == m_wm_take_focus) { + else if (((Atom)xcme.data.l[0]) == m_atom.WM_TAKE_FOCUS) { XWindowAttributes attr; Window fwin; int revert_to; @@ -1524,7 +1525,7 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, } /* Send a selection request */ - XConvertSelection(m_display, sel, target, m_xclip_out, win, CurrentTime); + XConvertSelection(m_display, sel, target, m_atom.XCLIP_OUT, win, CurrentTime); *context = XCLIB_XCOUT_SENTCONVSEL; return; @@ -1532,28 +1533,28 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, if (evt.type != SelectionNotify) return; - if (target == m_utf8_string && evt.xselection.property == None) { + if (target == m_atom.UTF8_STRING && evt.xselection.property == None) { *context = XCLIB_XCOUT_FALLBACK_UTF8; return; } - else if (target == m_compound_text && evt.xselection.property == None) { + else if (target == m_atom.COMPOUND_TEXT && evt.xselection.property == None) { *context = XCLIB_XCOUT_FALLBACK_COMP; return; } - else if (target == m_text && evt.xselection.property == None) { + else if (target == m_atom.TEXT && evt.xselection.property == None) { *context = XCLIB_XCOUT_FALLBACK_TEXT; return; } /* find the size and format of the data in property */ - XGetWindowProperty(m_display, win, m_xclip_out, 0, 0, False, + XGetWindowProperty(m_display, win, m_atom.XCLIP_OUT, 0, 0, False, AnyPropertyType, &pty_type, &pty_format, &pty_items, &pty_size, &buffer); XFree(buffer); - if (pty_type == m_incr) { + if (pty_type == m_atom.INCR) { /* start INCR mechanism by deleting property */ - XDeleteProperty(m_display, win, m_xclip_out); + XDeleteProperty(m_display, win, m_atom.XCLIP_OUT); XFlush(m_display); *context = XCLIB_XCOUT_INCR; return; @@ -1568,12 +1569,12 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, } // not using INCR mechanism, just read the property - XGetWindowProperty(m_display, win, m_xclip_out, 0, (long) pty_size, + XGetWindowProperty(m_display, win, m_atom.XCLIP_OUT, 0, (long) pty_size, False, AnyPropertyType, &pty_type, &pty_format, &pty_items, &pty_size, &buffer); /* finished with property, delete it */ - XDeleteProperty(m_display, win, m_xclip_out); + XDeleteProperty(m_display, win, m_atom.XCLIP_OUT); /* copy the buffer to the pointer for returned data */ ltxt = (unsigned char *) malloc(pty_items); @@ -1606,7 +1607,7 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, return; /* check size and format of the property */ - XGetWindowProperty(m_display, win, m_xclip_out, 0, 0, False, + XGetWindowProperty(m_display, win, m_atom.XCLIP_OUT, 0, 0, False, AnyPropertyType, &pty_type, &pty_format, &pty_items, &pty_size, &buffer); @@ -1615,14 +1616,14 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, * to tell the other X client that we have read * it and to send the next property */ XFree(buffer); - XDeleteProperty(m_display, win, m_xclip_out); + XDeleteProperty(m_display, win, m_atom.XCLIP_OUT); return; } if (pty_size == 0) { /* no more data, exit from loop */ XFree(buffer); - XDeleteProperty(m_display, win, m_xclip_out); + XDeleteProperty(m_display, win, m_atom.XCLIP_OUT); *context = XCLIB_XCOUT_NONE; /* this means that an INCR transfer is now @@ -1634,7 +1635,7 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, /* if we have come this far, the property contains * text, we know the size. */ - XGetWindowProperty(m_display, win, m_xclip_out, 0, (long) pty_size, + XGetWindowProperty(m_display, win, m_atom.XCLIP_OUT, 0, (long) pty_size, False, AnyPropertyType, &pty_type, &pty_format, &pty_items, &pty_size, &buffer); @@ -1655,7 +1656,7 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, XFree(buffer); /* delete property to get the next item */ - XDeleteProperty(m_display, win, m_xclip_out); + XDeleteProperty(m_display, win, m_atom.XCLIP_OUT); XFlush(m_display); return; } @@ -1665,7 +1666,7 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, GHOST_TUns8 *GHOST_SystemX11::getClipboard(bool selection) const { Atom sseln; - Atom target = m_utf8_string; + Atom target = m_atom.UTF8_STRING; Window owner; /* from xclip.c doOut() v0.11 */ @@ -1675,9 +1676,9 @@ GHOST_TUns8 *GHOST_SystemX11::getClipboard(bool selection) const unsigned int context = XCLIB_XCOUT_NONE; if (selection == True) - sseln = m_primary; + sseln = m_atom.PRIMARY; else - sseln = m_clipboard; + sseln = m_atom.CLIPBOARD; vector<GHOST_IWindow *> & win_vec = m_windowManager->getWindows(); vector<GHOST_IWindow *>::iterator win_it = win_vec.begin(); @@ -1687,7 +1688,7 @@ GHOST_TUns8 *GHOST_SystemX11::getClipboard(bool selection) const /* check if we are the owner. */ owner = XGetSelectionOwner(m_display, sseln); if (owner == win) { - if (sseln == m_clipboard) { + if (sseln == m_atom.CLIPBOARD) { sel_buf = (unsigned char *)malloc(strlen(txt_cut_buffer) + 1); strcpy((char *)sel_buf, txt_cut_buffer); return sel_buf; @@ -1712,19 +1713,19 @@ GHOST_TUns8 *GHOST_SystemX11::getClipboard(bool selection) const /* fallback is needed. set XA_STRING to target and restart the loop. */ if (context == XCLIB_XCOUT_FALLBACK) { context = XCLIB_XCOUT_NONE; - target = m_string; + target = m_atom.STRING; continue; } else if (context == XCLIB_XCOUT_FALLBACK_UTF8) { /* utf8 fail, move to compouned text. */ context = XCLIB_XCOUT_NONE; - target = m_compound_text; + target = m_atom.COMPOUND_TEXT; continue; } else if (context == XCLIB_XCOUT_FALLBACK_COMP) { /* compouned text faile, move to text. */ context = XCLIB_XCOUT_NONE; - target = m_text; + target = m_atom.TEXT; continue; } @@ -1741,7 +1742,7 @@ GHOST_TUns8 *GHOST_SystemX11::getClipboard(bool selection) const memcpy((char *)tmp_data, (char *)sel_buf, sel_len); tmp_data[sel_len] = '\0'; - if (sseln == m_string) + if (sseln == m_atom.STRING) XFree(sel_buf); else free(sel_buf); @@ -1762,8 +1763,8 @@ void GHOST_SystemX11::putClipboard(GHOST_TInt8 *buffer, bool selection) const if (buffer) { if (selection == False) { - XSetSelectionOwner(m_display, m_clipboard, m_window, CurrentTime); - owner = XGetSelectionOwner(m_display, m_clipboard); + XSetSelectionOwner(m_display, m_atom.CLIPBOARD, m_window, CurrentTime); + owner = XGetSelectionOwner(m_display, m_atom.CLIPBOARD); if (txt_cut_buffer) free((void *)txt_cut_buffer); @@ -1771,8 +1772,8 @@ void GHOST_SystemX11::putClipboard(GHOST_TInt8 *buffer, bool selection) const strcpy(txt_cut_buffer, buffer); } else { - XSetSelectionOwner(m_display, m_primary, m_window, CurrentTime); - owner = XGetSelectionOwner(m_display, m_primary); + XSetSelectionOwner(m_display, m_atom.PRIMARY, m_window, CurrentTime); + owner = XGetSelectionOwner(m_display, m_atom.PRIMARY); if (txt_select_buffer) free((void *)txt_select_buffer); @@ -1944,7 +1945,7 @@ void GHOST_SystemX11::initXInputDevices() if ((m_xtablet.StylusDevice == NULL) && - (is_stylus(device_info[i].name, device_type) || (device_info[i].type == m_xi_tablet))) + (is_stylus(device_info[i].name, device_type) || (device_info[i].type == m_atom.TABLET))) { // printf("\tfound stylus\n"); m_xtablet.StylusID = device_info[i].id; diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h index 69ae634bb25..a11aea240be 100644 --- a/intern/ghost/intern/GHOST_SystemX11.h +++ b/intern/ghost/intern/GHOST_SystemX11.h @@ -274,37 +274,6 @@ public: return 0; } - /** - * Atom used for ICCCM, WM-spec and Motif. - * We only need get this atom at the start, it's relative - * to the display not the window and are public for every - * window that need it. - */ - Atom m_wm_state; - Atom m_wm_change_state; - Atom m_net_state; - Atom m_net_max_horz; - Atom m_net_max_vert; - Atom m_net_fullscreen; - Atom m_motif; - Atom m_wm_take_focus; - Atom m_wm_protocols; - Atom m_delete_window_atom; - - /* Atoms for Selection, copy & paste. */ - Atom m_targets; - Atom m_string; - Atom m_compound_text; - Atom m_text; - Atom m_clipboard; - Atom m_primary; - Atom m_xclip_out; - Atom m_incr; - Atom m_utf8_string; -#ifdef WITH_X11_XINPUT - Atom m_xi_tablet; -#endif - #ifdef WITH_X11_XINPUT typedef struct GHOST_TabletX11 { XDevice *StylusDevice; @@ -326,6 +295,39 @@ public: } #endif // WITH_X11_XINPUT + struct { + /** + * Atom used for ICCCM, WM-spec and Motif. + * We only need get this atom at the start, it's relative + * to the display not the window and are public for every + * window that need it. + */ + Atom WM_STATE; + Atom WM_CHANGE_STATE; + Atom _NET_WM_STATE; + Atom _NET_WM_STATE_MAXIMIZED_HORZ; + Atom _NET_WM_STATE_MAXIMIZED_VERT; + Atom _NET_WM_STATE_FULLSCREEN; + Atom _MOTIF_WM_HINTS; + Atom WM_TAKE_FOCUS; + Atom WM_PROTOCOLS; + Atom WM_DELETE_WINDOW; + + /* Atoms for Selection, copy & paste. */ + Atom TARGETS; + Atom STRING; + Atom COMPOUND_TEXT; + Atom TEXT; + Atom CLIPBOARD; + Atom PRIMARY; + Atom XCLIP_OUT; + Atom INCR; + Atom UTF8_STRING; +#ifdef WITH_X11_XINPUT + Atom TABLET; +#endif + } m_atom; + private: Display *m_display; diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp index 7ef3a739b7e..50520b7eda5 100644 --- a/intern/ghost/intern/GHOST_WindowX11.cpp +++ b/intern/ghost/intern/GHOST_WindowX11.cpp @@ -395,16 +395,16 @@ GHOST_WindowX11( XFree(xclasshint); /* The basic for a good ICCCM "work" */ - if (m_system->m_wm_protocols) { + if (m_system->m_atom.WM_PROTOCOLS) { natom = 0; - if (m_system->m_delete_window_atom) { - atoms[natom] = m_system->m_delete_window_atom; + if (m_system->m_atom.WM_DELETE_WINDOW) { + atoms[natom] = m_system->m_atom.WM_DELETE_WINDOW; natom++; } - if (m_system->m_wm_take_focus) { - atoms[natom] = m_system->m_wm_take_focus; + if (m_system->m_atom.WM_TAKE_FOCUS) { + atoms[natom] = m_system->m_atom.WM_TAKE_FOCUS; natom++; } @@ -744,7 +744,7 @@ void GHOST_WindowX11::icccmSetState(int state) xev.xclient.display = m_display; xev.xclient.window = m_window; xev.xclient.format = 32; - xev.xclient.message_type = m_system->m_wm_change_state; + xev.xclient.message_type = m_system->m_atom.WM_CHANGE_STATE; xev.xclient.data.l[0] = state; XSendEvent(m_display, RootWindow(m_display, DefaultScreen(m_display)), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev); @@ -758,8 +758,8 @@ int GHOST_WindowX11::icccmGetState(void) const int format_ret, st; prop_ret = NULL; - st = XGetWindowProperty(m_display, m_window, m_system->m_wm_state, 0, - 0x7fffffff, False, m_system->m_wm_state, &type_ret, + st = XGetWindowProperty(m_display, m_window, m_system->m_atom.WM_STATE, 0, + 0x7fffffff, False, m_system->m_atom.WM_STATE, &type_ret, &format_ret, &num_ret, &bytes_after, &prop_ret); if ((st == Success) && (prop_ret) && (num_ret == 2)) @@ -780,7 +780,7 @@ void GHOST_WindowX11::netwmMaximized(bool set) xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.window = m_window; - xev.xclient.message_type = m_system->m_net_state; + xev.xclient.message_type = m_system->m_atom._NET_WM_STATE; xev.xclient.format = 32; if (set == True) @@ -788,8 +788,8 @@ void GHOST_WindowX11::netwmMaximized(bool set) else xev.xclient.data.l[0] = _NET_WM_STATE_REMOVE; - xev.xclient.data.l[1] = m_system->m_net_max_horz; - xev.xclient.data.l[2] = m_system->m_net_max_vert; + xev.xclient.data.l[1] = m_system->m_atom._NET_WM_STATE_MAXIMIZED_HORZ; + xev.xclient.data.l[2] = m_system->m_atom._NET_WM_STATE_MAXIMIZED_VERT; xev.xclient.data.l[3] = 0; xev.xclient.data.l[4] = 0; XSendEvent(m_display, RootWindow(m_display, DefaultScreen(m_display)), @@ -806,15 +806,15 @@ bool GHOST_WindowX11::netwmIsMaximized(void) const prop_ret = NULL; st = False; - ret = XGetWindowProperty(m_display, m_window, m_system->m_net_state, 0, + ret = XGetWindowProperty(m_display, m_window, m_system->m_atom._NET_WM_STATE, 0, 0x7fffffff, False, XA_ATOM, &type_ret, &format_ret, &num_ret, &bytes_after, &prop_ret); if ((ret == Success) && (prop_ret) && (format_ret == 32)) { count = 0; for (i = 0; i < num_ret; i++) { - if (((unsigned long *) prop_ret)[i] == m_system->m_net_max_horz) + if (((unsigned long *) prop_ret)[i] == m_system->m_atom._NET_WM_STATE_MAXIMIZED_HORZ) count++; - if (((unsigned long *) prop_ret)[i] == m_system->m_net_max_vert) + if (((unsigned long *) prop_ret)[i] == m_system->m_atom._NET_WM_STATE_MAXIMIZED_VERT) count++; if (count == 2) { st = True; @@ -836,7 +836,7 @@ void GHOST_WindowX11::netwmFullScreen(bool set) xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.window = m_window; - xev.xclient.message_type = m_system->m_net_state; + xev.xclient.message_type = m_system->m_atom._NET_WM_STATE; xev.xclient.format = 32; if (set == True) @@ -844,7 +844,7 @@ void GHOST_WindowX11::netwmFullScreen(bool set) else xev.xclient.data.l[0] = _NET_WM_STATE_REMOVE; - xev.xclient.data.l[1] = m_system->m_net_fullscreen; + xev.xclient.data.l[1] = m_system->m_atom._NET_WM_STATE_FULLSCREEN; xev.xclient.data.l[2] = 0; xev.xclient.data.l[3] = 0; xev.xclient.data.l[4] = 0; @@ -862,12 +862,12 @@ bool GHOST_WindowX11::netwmIsFullScreen(void) const prop_ret = NULL; st = False; - ret = XGetWindowProperty(m_display, m_window, m_system->m_net_state, 0, + ret = XGetWindowProperty(m_display, m_window, m_system->m_atom._NET_WM_STATE, 0, 0x7fffffff, False, XA_ATOM, &type_ret, &format_ret, &num_ret, &bytes_after, &prop_ret); if ((ret == Success) && (prop_ret) && (format_ret == 32)) { for (i = 0; i < num_ret; i++) { - if (((unsigned long *) prop_ret)[i] == m_system->m_net_fullscreen) { + if (((unsigned long *) prop_ret)[i] == m_system->m_atom._NET_WM_STATE_FULLSCREEN) { st = True; break; } @@ -889,8 +889,8 @@ void GHOST_WindowX11::motifFullScreen(bool set) else hints.decorations = 1; - XChangeProperty(m_display, m_window, m_system->m_motif, - m_system->m_motif, 32, PropModeReplace, + XChangeProperty(m_display, m_window, m_system->m_atom._MOTIF_WM_HINTS, + m_system->m_atom._MOTIF_WM_HINTS, 32, PropModeReplace, (unsigned char *) &hints, 4); } @@ -905,8 +905,8 @@ bool GHOST_WindowX11::motifIsFullScreen(void) const prop_ret = NULL; state = False; - st = XGetWindowProperty(m_display, m_window, m_system->m_motif, 0, - 0x7fffffff, False, m_system->m_motif, + st = XGetWindowProperty(m_display, m_window, m_system->m_atom._MOTIF_WM_HINTS, 0, + 0x7fffffff, False, m_system->m_atom._MOTIF_WM_HINTS, &type_ret, &format_ret, &num_ret, &bytes_after, &prop_ret); if ((st == Success) && (prop_ret)) { |