-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDxWindowLinux.cpp
More file actions
138 lines (111 loc) · 3.69 KB
/
DxWindowLinux.cpp
File metadata and controls
138 lines (111 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#define DX_MAKE
#include "DxWindowLinux.h"
#ifndef DX_NON_NAMESPACE
namespace DxLib
{
#endif // DX_NON_NAMESPACE
extern int NS_GetWindowSize(int *Width, int *Height){
*Width = GLINUX.Device.Screen.Width;
*Height = GLINUX.Device.Screen.Height;
return 0;
}
extern int NS_SetMainWindowText(const TCHAR *WindowText){
Display* d = GLINUX.Device.Screen.XDisplay;
Window w = GLINUX.Device.Screen.XWindow;
// [本家非互換]ウィンドウが存在していない場合は反映されない
if((!d)||(!w)){
return -1;
}
Xutf8SetWMProperties(d, w, WindowText, NULL, NULL, 0, NULL, NULL, NULL);
return 0;
}
extern int NS_SetDragFileValidFlag(int Flag){
Display* d = GLINUX.Device.Screen.XDisplay;
Window w = GLINUX.Device.Screen.XWindow;
if((!d)||(!w)){
return -1;
}
if(Flag){
Atom xdndVer = 5;
XChangeProperty(d, w, GLINUX.Device.Screen._atom_XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*)&xdndVer, 1);
}else{
XDeleteProperty(d, w, GLINUX.Device.Screen._atom_XdndAware);
}
return 0;
}
extern int NS_DragFileInfoClear(){
if(GLINUX.Device.Screen._xdnd_bufPtr){
DXFREE(GLINUX.Device.Screen._xdnd_bufPtr);
GLINUX.Device.Screen._xdnd_bufPtr = NULL;
}
GLINUX.Device.Screen._xdnd_bufLen = 0;
GLINUX.Device.Screen._xdnd_bufPos = 0;
GLINUX.Device.Screen._xdnd_bufNum = 0;
return 0;
}
/*
内部挙動メモ
R: \r
N: \n
Z: \0
(2ファイル落とす)
_buf: [file://fooRNfile://hogeRN]
_len: 23
(1回目 - 読んだ所までposを移動)
pos: [^ ]0
buf: [file://fooZ]
ret: 11
(2回目 - 末端に到達するとバッファをクリア)
pos: [ ^ ]12
buf: [file://hogeZ]
ret: 12
_buf: (null)
pos: []0
(3回目 - もうファイルはない)
ret: -1
(バッファが短い場合を含む各挙動)
buf=abcdefghRN
GetDragFilePath(NULL)、バッファ空 -> ret: -1
GetDragFilePath(NULL)、バッファあり -> ret: 直後のパス長(含む\0: 10)
GetDragFilePath(path)、バッファ空 -> ret: -1
GetDragFilePath(path)、バッファあり -> ret: 0, path=abcdefghZ
GetDragFilePath(path, 5) -> ret: 0, path=abcdZ
*/
extern int NS_GetDragFilePath(TCHAR *FilePathBuffer, int FilePathBufferBytes){
if(!GLINUX.Device.Screen._xdnd_bufPtr){
return -1;
}
int nextPathLen = 0;
for(int i=GLINUX.Device.Screen._xdnd_bufPos; i<GLINUX.Device.Screen._xdnd_bufLen; i++){
if(GLINUX.Device.Screen._xdnd_bufPtr[i] == '\r'){ // to conclude i+1 is \n
nextPathLen = i-GLINUX.Device.Screen._xdnd_bufPos; // without \0
break;
}
}
if(!FilePathBuffer){ // FilePathBuffer is null, return size (with \0) instead
return nextPathLen + 1;
}else{
int nextRetPathLen = nextPathLen;
if(nextPathLen >= FilePathBufferBytes){
nextRetPathLen = FilePathBufferBytes-1;
}
_MEMCPY(FilePathBuffer, GLINUX.Device.Screen._xdnd_bufPtr+GLINUX.Device.Screen._xdnd_bufPos, nextRetPathLen);
FilePathBuffer[nextPathLen] = '\0';
if(GLINUX.Device.Screen._xdnd_bufLen == GLINUX.Device.Screen._xdnd_bufPos+nextPathLen+2){ // if last path of buf, free buf
DXFREE(GLINUX.Device.Screen._xdnd_bufPtr);
GLINUX.Device.Screen._xdnd_bufPtr = NULL;
GLINUX.Device.Screen._xdnd_bufLen = 0;
GLINUX.Device.Screen._xdnd_bufPos = 0;
}else{
GLINUX.Device.Screen._xdnd_bufPos += nextPathLen+2;
}
GLINUX.Device.Screen._xdnd_bufNum--;
}
return 0;
}
extern int NS_GetDragFileNum(){
return GLINUX.Device.Screen._xdnd_bufNum;
}
#ifndef DX_NON_NAMESPACE
}
#endif // DX_NON_NAMESPACE