comparison dynamin/gui/x_clipboard.d @ 106:acdbb30fee7e

Port to D2. Most of the effort was dealing with immutable and const.
author Jordan Miner <jminer7@gmail.com>
date Mon, 17 Dec 2012 23:41:50 -0600
parents 73060bc3f004
children
comparison
equal deleted inserted replaced
105:97997a544ac0 106:acdbb30fee7e
39 return (e.type == SelectionRequest || e.type == SelectionNotify) && 39 return (e.type == SelectionRequest || e.type == SelectionNotify) &&
40 e.xany.window == msgWin; 40 e.xany.window == msgWin;
41 41
42 } 42 }
43 43
44 string backend_getSelText(XAtom sel, ref ClipboardData data) { 44 mstring backend_getSelText(XAtom sel, ref ClipboardData data) {
45 XConvertSelection(display, sel, XA.UTF8_STRING, XA.DYNAMIN_SELECTION, msgWin, CurrentTime); 45 XConvertSelection(display, sel, XA.UTF8_STRING, XA.DYNAMIN_SELECTION, msgWin, CurrentTime);
46 XSync(display, false); 46 XSync(display, false);
47 auto start = Environment.runningTime; 47 auto start = Environment.runningTime;
48 XEvent ev; 48 XEvent ev;
49 while(true) { 49 while(true) {
64 char* propData = cast(char*)getXWindowProperty(display, msgWin, 64 char* propData = cast(char*)getXWindowProperty(display, msgWin,
65 selEv.property, &count); 65 selEv.property, &count);
66 scope(exit) XFree(propData); 66 scope(exit) XFree(propData);
67 XDeleteProperty(display, msgWin, selEv.property); 67 XDeleteProperty(display, msgWin, selEv.property);
68 68
69 string str = new char[count]; 69 mstring str = new char[count];
70 str[] = propData[0..count]; 70 str[] = propData[0..count];
71 return str; 71 return str;
72 } 72 }
73 } 73 }
74 struct ClipboardData { 74 struct ClipboardData {
75 XAtom target; 75 XAtom target;
76 char* data; 76 char* data;
77 uint length; // number of bytes in data 77 uint length; // number of bytes in data
78 } 78 }
79 // always called from the event thread...don't have to avoid static data 79 // always called from the event thread...don't have to avoid static data
80 void backend_setSelText(XAtom sel, string text, ref ClipboardData data) { 80 void backend_setSelText(XAtom sel, cstring text, ref ClipboardData data) {
81 XSetSelectionOwner(display, sel, msgWin, CurrentTime); 81 XSetSelectionOwner(display, sel, msgWin, CurrentTime);
82 data.target = XA.UTF8_STRING; 82 data.target = XA.UTF8_STRING;
83 data.data = text.ptr; 83 data.data = text.ptr;
84 data.length = text.length; 84 data.length = text.length;
85 85
86 XConvertSelection(display, XA.CLIPBOARD_MANAGER, XA.SAVE_TARGETS, None, msgWin, CurrentTime); 86 XConvertSelection(display, XA.CLIPBOARD_MANAGER, XA.SAVE_TARGETS, None, msgWin, CurrentTime);
87 } 87 }
88 88
89 template ClipboardBackend() { 89 template ClipboardBackend() {
90 ClipboardData data; // make array when supporting multiple types (PNG & BMP) 90 ClipboardData data; // make array when supporting multiple types (PNG & BMP)
91 void backend_setText(string text) { 91 void backend_setText(cstring text) {
92 backend_setSelText(XA.CLIPBOARD, text, data); 92 backend_setSelText(XA.CLIPBOARD, text, data);
93 } 93 }
94 string backend_getText() { 94 mstring backend_getText() {
95 return backend_getSelText(XA.CLIPBOARD, data); 95 return backend_getSelText(XA.CLIPBOARD, data);
96 } 96 }
97 bool backend_containsText() { 97 bool backend_containsText() {
98 return backend_getText() != null; 98 return backend_getText() != null;
99 } 99 }
100 } 100 }
101 101
102 template SelectionBackend() { 102 template SelectionBackend() {
103 ClipboardData data; // make array when supporting multiple types (PNG & BMP) 103 ClipboardData data; // make array when supporting multiple types (PNG & BMP)
104 void backend_setText(string text) { 104 void backend_setText(cstring text) {
105 backend_setSelText(XA.PRIMARY, text, data); 105 backend_setSelText(XA.PRIMARY, text, data);
106 } 106 }
107 string backend_getText() { 107 mstring backend_getText() {
108 return backend_getSelText(XA.PRIMARY, data); 108 return backend_getSelText(XA.PRIMARY, data);
109 } 109 }
110 bool backend_containsText() { 110 bool backend_containsText() {
111 return backend_getText() != null; 111 return backend_getText() != null;
112 } 112 }