Setting up code for multiple targets.
This commit is contained in:
		
							
								
								
									
										22
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/main.c
									
									
									
									
									
								
							| @@ -51,7 +51,7 @@ void get_selection(Atom property) { | |||||||
| 	incr = XInternAtom(display, "INCR", 0); | 	incr = XInternAtom(display, "INCR", 0); | ||||||
| 	if(type == incr) | 	if(type == incr) | ||||||
| 	{ | 	{ | ||||||
| 		// TODO: increment size of buffer | 		// TODO: prepare for multiple messages | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -93,7 +93,7 @@ void send_reject(XSelectionRequestEvent *sre) { | |||||||
| 			NoEventMask, (XEvent*)&reply_se); | 			NoEventMask, (XEvent*)&reply_se); | ||||||
| } | } | ||||||
|  |  | ||||||
| void send_selection(XSelectionRequestEvent *sre, Atom utf8) | void send_selection(XSelectionRequestEvent *sre, Atom target) | ||||||
| { | { | ||||||
| 	XSelectionEvent reply_se; | 	XSelectionEvent reply_se; | ||||||
|  |  | ||||||
| @@ -106,7 +106,7 @@ void send_selection(XSelectionRequestEvent *sre, Atom utf8) | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| 	XChangeProperty(display, sre->requestor, sre->property, | 	XChangeProperty(display, sre->requestor, sre->property, | ||||||
| 			utf8, 8, PropModeReplace, (unsigned char*)data, data_size); | 			target, 8, PropModeReplace, (unsigned char*)data, data_size); | ||||||
|  |  | ||||||
| 	reply_se.type = SelectionNotify; | 	reply_se.type = SelectionNotify; | ||||||
| 	reply_se.requestor = sre->requestor; | 	reply_se.requestor = sre->requestor; | ||||||
| @@ -122,7 +122,9 @@ void send_selection(XSelectionRequestEvent *sre, Atom utf8) | |||||||
| int main() { | int main() { | ||||||
| 	Window root, owner; | 	Window root, owner; | ||||||
| 	int screen; | 	int screen; | ||||||
| 	Atom selection, utf8, clip_property; | 	Atom selection, clip_property; | ||||||
|  | 	// target atoms | ||||||
|  | 	Atom utf8_target, text_target, string_target; | ||||||
| 	data = NULL; | 	data = NULL; | ||||||
| 	data_size = 0; | 	data_size = 0; | ||||||
|  |  | ||||||
| @@ -143,7 +145,9 @@ int main() { | |||||||
|  |  | ||||||
| 	// create atoms for selections | 	// create atoms for selections | ||||||
| 	selection = XInternAtom(display, "CLIPBOARD", 0); | 	selection = XInternAtom(display, "CLIPBOARD", 0); | ||||||
| 	utf8 = XInternAtom(display, "UTF8_STRING", 0); | 	utf8_target = XInternAtom(display, "UTF8_STRING", 0); | ||||||
|  | 	text_target = XInternAtom(display, "TEXT", 0); | ||||||
|  | 	string_target = XInternAtom(display, "STRING", 0); | ||||||
| 	clip_property = XInternAtom(display, "TINYCLIP", 0); | 	clip_property = XInternAtom(display, "TINYCLIP", 0); | ||||||
|  |  | ||||||
| 	// check if there is currently someone using the clipboard | 	// check if there is currently someone using the clipboard | ||||||
| @@ -154,7 +158,7 @@ int main() { | |||||||
| #ifdef DEBUG | #ifdef DEBUG | ||||||
| 		printf("Current owner: 0x%1X\n", (unsigned int)owner); | 		printf("Current owner: 0x%1X\n", (unsigned int)owner); | ||||||
| #endif | #endif | ||||||
| 		XConvertSelection(display, selection, utf8, | 		XConvertSelection(display, selection, utf8_target, | ||||||
| 				clip_property, clip_win, CurrentTime); | 				clip_property, clip_win, CurrentTime); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| @@ -178,7 +182,7 @@ int main() { | |||||||
| 		{ | 		{ | ||||||
| 			case SelectionClear: | 			case SelectionClear: | ||||||
| 				// if someone else took the clipboard, regain ownership | 				// if someone else took the clipboard, regain ownership | ||||||
| 				XConvertSelection(display, selection, utf8, | 				XConvertSelection(display, selection, utf8_target, | ||||||
| 						clip_property, clip_win, CurrentTime); | 						clip_property, clip_win, CurrentTime); | ||||||
| 				break; | 				break; | ||||||
| 			case SelectionNotify: | 			case SelectionNotify: | ||||||
| @@ -197,10 +201,10 @@ int main() { | |||||||
| 				printf("New selection request:\n" | 				printf("New selection request:\n" | ||||||
| 						"  requestor: 0x%1x\n", (unsigned int)sre->requestor); | 						"  requestor: 0x%1x\n", (unsigned int)sre->requestor); | ||||||
| #endif | #endif | ||||||
| 				if(sre->target != utf8 || sre->property == None) | 				if(sre->target != utf8_target || sre->property == None) | ||||||
| 					send_reject(sre); | 					send_reject(sre); | ||||||
| 				else | 				else | ||||||
| 					send_selection(sre, utf8); | 					send_selection(sre, utf8_target); | ||||||
| 				break; | 				break; | ||||||
| 			case ClientMessage: | 			case ClientMessage: | ||||||
| 				break; | 				break; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user