예제 #1
0
파일: gui.c 프로젝트: outgame/CrayonPhysics
int main (int argc, char *argv[]){
  Gui *gui = (Gui *)malloc(sizeof(Gui));;
  gui->space = cpSpaceNew();
  gui->current_body = NULL;
  cpSpaceSetGravity(gui->space, cpv(0, GRAVITY));
  cpEnableSegmentToSegmentCollisions();
  
  gtk_init(&argc, &argv); 

  initialize_window(gui);

  initialize_client(gui);  
  
  pthread_t t1;
  int iret1 = pthread_create(&t1, NULL, client_recv1, gui);

  gtk_main();
  
  cpSpaceFree(gui->space);
  free(gui);
  return 0;
}
예제 #2
0
int main(int argc, char *argv[])
{
	int s;
	uint32_t whitelist_start = 0;
	uint32_t whitelist_end = 0;	
	uint16_t port = NETISO_PORT;
	
#ifndef WIN32	
	if (sizeof(off_t) < 8)
	{
		DPRINTF("off_t too small!\n");
		return -1;
	}
#endif
	
	if (argc < 2)
	{
		printf("Usage: %s rootdirectory [port] [whitelist]\nDefault port: %d\nWhitelist: x.x.x.x, where x is 0-255 or * (e.g 192.168.1.* to allow only connections from 192.168.1.0-192.168.1.255)\n", argv[0], NETISO_PORT);
		return -1;
	}
	
	if (strlen(argv[1]) >= sizeof(root_directory))
	{
		printf("Directory name too long!\n");
		return -1;
	}
	
	strcpy(root_directory, argv[1]);
	
	for (int i = strlen(root_directory)-1; i>= 0; i--)
	{
		if (root_directory[i] == '/' || root_directory[i] == '\\')
			root_directory[i] = 0;
		else
			break;
	}
	
	if (strlen(root_directory) == 0)
	{
		printf("/ can't be specified as root directory!\n");
		return -1;
	}
	
	if (argc > 2)
	{
		uint32_t u;
		
		if (sscanf(argv[2], "%u", &u) != 1)
		{
			printf("Wrong port specified.\n");
			return -1;
		}
		
#ifdef WIN32
		uint32_t min = 1;
#else
		uint32_t min = 1024;
#endif
		
		if (u < min || u > 65535)
		{
			printf("Port must be in %d-65535 range.\n", min);
			return -1;
		}
		
		port = u;
	}
	
	if (argc > 3)
	{
		char *p = argv[3];
		
		for (int i = 3; i >= 0; i--)
		{
			uint32_t u;
			int wildcard = 0;
			
			if (sscanf(p, "%u", &u) != 1)
			{
				if (i == 0)
				{
					if (strcmp(p, "*") != 0)
					{
						printf("Wrong whitelist format.\n");
						return -1;
					}					
					
				}
				else
				{
					if (p[0] != '*' || p[1] != '.')
					{
						printf("Wrong whitelist format.\n");
						return -1;
					}
				}
				
				wildcard = 1;
			}
			else
			{
				if (u > 0xFF)
				{
					printf("Wrong whitelist format.\n");
					return -1;
				}
			}
			
			if (wildcard)
			{
				whitelist_end |= (0xFF<<(i*8));
			}
			else
			{
				whitelist_start |= (u<<(i*8));
				whitelist_end |= (u<<(i*8));
			}
			
			if (i != 0)
			{
				p = strchr(p, '.');
				if (!p)
				{
					printf("Wrong whitelist format.\n");
					return -1;
				}
				
				p++;
			}
		}
		
		DPRINTF("Whitelist: %08X-%08X\n", whitelist_start, whitelist_end);
	}
	
	s = initialize_socket(port);
	if (s < 0)
	{
		printf("Error in initialization.\n");
		return -1;
	}	
	
	memset(clients, 0, sizeof(clients));
	printf("Waiting for client...\n");
	
	for (;;)
	{
		struct sockaddr_in addr;
		unsigned int size;
		int cs;
		int i;
		
		size = sizeof(addr);
		cs = accept(s, (struct sockaddr *)&addr, (socklen_t *)&size);
		
		if (cs < 0)
		{
			DPRINTF("Accept error: %d\n", get_network_error());
			printf("Network error.\n");
			break;
		}
		
		
		// Check for same client
		for (i = 0; i < MAX_CLIENTS; i++)
		{
			if (clients[i].connected && clients[i].ip_addr.s_addr == addr.sin_addr.s_addr)
				break;			
		}
		
		if (i != MAX_CLIENTS)
		{
			// Shutdown socket and wait for thread to complete
			shutdown(clients[i].s, SHUT_RDWR);
			closesocket(clients[i].s);
			join_thread(clients[i].thread);
			printf("Reconnection from %s\n",  inet_ntoa(addr.sin_addr));
		}
		else
		{
			if (whitelist_start != 0)
			{
				uint32_t ip = BE32(addr.sin_addr.s_addr);
				
				if (ip < whitelist_start || ip > whitelist_end)
				{
					printf("Rejected connection from %s (not in whitelist)\n", inet_ntoa(addr.sin_addr));
					closesocket(cs);
					continue;
				}
			}
			
			for (i = 0; i < MAX_CLIENTS; i++)
			{
				if (!clients[i].connected)
					break;
			}
			
			if (i == MAX_CLIENTS)
			{
				printf("Too many connections! (rejected client: %s)\n", inet_ntoa(addr.sin_addr));
				closesocket(cs);
				continue;
			}			
			
			printf("Connection from %s\n",  inet_ntoa(addr.sin_addr));
		}
		
		if (initialize_client(&clients[i]) != 0)
		{
			printf("System seems low in resources.\n");
			break;
		}
		
		clients[i].s = cs;
		clients[i].ip_addr = addr.sin_addr;		
		create_start_thread(&clients[i].thread, client_thread, &clients[i]);
	}
	
#ifdef WIN32
	WSACleanup();
#endif
	
	return 0;
}
예제 #3
0
int main(int argc, char *argv[])
{
	if (argc != 2 || !strlen(argv[1]))
	{
	fprintf(stderr, "%s [client name]\n", argv[0]);
	return 1;
	}

	if (!set_program_name(argv[0]) || !initialize_client())
	{
	fprintf(stderr, "%s: could not initialize client\n", argv[0]);
	client_cleanup();
	return 1;
	}

	load_internal_plugins();

	if (!start_message_queue())
	{
	fprintf(stderr, "%s: could not start message queue\n", argv[0]);
	client_cleanup();
	return 1;
	}

	if (!register_resource_client(NULL))
	{
	fprintf(stderr, "%s: could not register client\n", argv[0]);
	stop_message_queue();
	client_cleanup();
	return 1;
	}

	command_handle new_service = register_service(argv[1], PARAM_ECHO_TYPE);
	command_reference service_status = 0;

	if ( !new_service || !(service_status = send_command(new_service)) ||
	     !(wait_command_event(service_status, event_complete, local_default_timeout()) & event_complete) )
	{
	fprintf(stderr, "%s: could not register service\n", argv[0]);
	if (new_service)    destroy_command(new_service);
	if (service_status) clear_command_status(service_status);
	stop_message_queue();
	client_cleanup();
	return 1;
	}

	destroy_command(new_service);
	clear_command_status(service_status);

	set_log_client_name(argv[1]);

	if (!stop_message_queue())
	{
	client_cleanup();
	return 1;
	}

	set_queue_event_hook(&message_queue_hook);

	result outcome = inline_message_queue();
	client_cleanup();
	return outcome? 0 : 1;
}
예제 #4
0
파일: window.c 프로젝트: Stebalien/bspwm
void manage_window(xcb_window_t win, rule_consequence_t *csq, int fd)
{
	monitor_t *m = mon;
	desktop_t *d = mon->desk;
	node_t *f = mon->desk->focus;

	parse_rule_consequence(fd, csq);

	if (!csq->manage) {
		free(csq->layer);
		free(csq->state);
		window_show(win);
		return;
	}

	if (csq->node_desc[0] != '\0') {
		coordinates_t ref = {m, d, f};
		coordinates_t trg = {NULL, NULL, NULL};
		if (node_from_desc(csq->node_desc, &ref, &trg)) {
			m = trg.monitor;
			d = trg.desktop;
			f = trg.node;
		}
	} else if (csq->desktop_desc[0] != '\0') {
		coordinates_t ref = {m, d, NULL};
		coordinates_t trg = {NULL, NULL, NULL};
		if (desktop_from_desc(csq->desktop_desc, &ref, &trg)) {
			m = trg.monitor;
			d = trg.desktop;
			f = trg.desktop->focus;
		}
	} else if (csq->monitor_desc[0] != '\0') {
		coordinates_t ref = {m, NULL, NULL};
		coordinates_t trg = {NULL, NULL, NULL};
		if (monitor_from_desc(csq->monitor_desc, &ref, &trg)) {
			m = trg.monitor;
			d = trg.monitor->desk;
			f = trg.monitor->desk->focus;
		}
	}

	if (csq->sticky) {
		m = mon;
		d = mon->desk;
		f = mon->desk->focus;
	}

	if (csq->split_dir[0] != '\0' && f != NULL) {
		direction_t dir;
		if (parse_direction(csq->split_dir, &dir)) {
			presel_dir(m, d, f, dir);
		}
	}

	if (csq->split_ratio != 0 && f != NULL) {
		presel_ratio(m, d, f, csq->split_ratio);
	}

	node_t *n = make_node(win);
	client_t *c = make_client();
	c->border_width = csq->border ? d->border_width : 0;
	n->client = c;
	initialize_client(n);
	update_floating_rectangle(n);

	if (c->floating_rectangle.x == 0 && c->floating_rectangle.y == 0) {
		csq->center = true;
	}

	c->min_width = csq->min_width;
	c->max_width = csq->max_width;
	c->min_height = csq->min_height;
	c->max_height = csq->max_height;

	monitor_t *mm = monitor_from_client(c);
	embrace_client(mm, c);
	adapt_geometry(&mm->rectangle, &m->rectangle, n);

	if (csq->center) {
		window_center(m, c);
	}

	snprintf(c->class_name, sizeof(c->class_name), "%s", csq->class_name);
	snprintf(c->instance_name, sizeof(c->instance_name), "%s", csq->instance_name);

	f = insert_node(m, d, n, f);
	clients_count++;

	put_status(SBSC_MASK_NODE_MANAGE, "node_manage %s %s 0x%X 0x%X\n", m->name, d->name, win, f!=NULL?f->id:0);

	if (f != NULL && f->client != NULL && csq->state != NULL && *(csq->state) == STATE_FLOATING) {
		c->last_layer = c->layer = f->client->layer;
	}

	if (csq->layer != NULL) {
		c->last_layer = c->layer = *(csq->layer);
	}

	if (csq->state != NULL) {
		set_state(m, d, n, *(csq->state));
		c->last_state = c->state;
	}

	set_locked(m, d, n, csq->locked);
	set_sticky(m, d, n, csq->sticky);
	set_private(m, d, n, csq->private);

	arrange(m, d);

	bool give_focus = (csq->focus && (d == mon->desk || csq->follow));

	if (give_focus) {
		focus_node(m, d, n);
	} else if (csq->focus) {
		activate_node(m, d, n);
	} else {
		stack(d, n, false);
	}

	uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
	xcb_change_window_attributes(dpy, win, XCB_CW_EVENT_MASK, values);

	if (d == m->desk) {
		window_show(n->id);
	} else {
		window_hide(n->id);
	}

	/* the same function is already called in `focus_node` but has no effects on unmapped windows */
	if (give_focus) {
		xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME);
	}

	ewmh_set_wm_desktop(n, d);
	ewmh_update_client_list(false);
	free(csq->layer);
	free(csq->state);
}
예제 #5
0
int main(int argc, char *argv[])
{
	if (argc < 3 || !strlen(argv[1]))
	{
	fprintf(stderr, "%s [client name] [config file] (...)\n", argv[0]);
	return 1;
	}

	if (!set_program_name(argv[0]) || !initialize_client())
	{
	fprintf(stderr, "%s: could not initialize client\n", argv[0]);
	client_cleanup();
	return 1;
	}

	block_messages();

	if (!start_message_queue())
	{
	fprintf(stderr, "%s: could not start message queue\n", argv[0]);
	client_cleanup();
	return 1;
	}

	if (!register_admin_client(argv[1]))
	{
	fprintf(stderr, "%s: could not register client\n", argv[0]);
	stop_message_queue();
	client_cleanup();
	return 1;
	}

	command_handle new_monitor = set_monitor_flags(monitor_attached_clients);
	command_reference monitor_status = 0;

	if ( !new_monitor || !(monitor_status = send_command(new_monitor)) ||
	     !(wait_command_event(monitor_status, event_complete, local_default_timeout()) & event_complete) )
	{
	fprintf(stderr, "%s: could not monitor server\n", argv[0]);
	if (new_monitor)    destroy_command(new_monitor);
	if (monitor_status) clear_command_status(monitor_status);
	stop_message_queue();
	client_cleanup();
	return 1;
	}

	destroy_command(new_monitor);
	clear_command_status(monitor_status);


	int outcome = 0, I;

	for (I = 2; I < argc && outcome >= 0; I++)
	{
	int protocol_pid = -1;

	int config_fd = open_protocol_file(argv[I], &protocol_pid);
	if (config_fd < 0)
	 {
	if (config_fd == RSERVR_FILE_ERROR)
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], strerror(errno));
	if (config_fd == RSERVR_PROTOCOL_ERROR)
	/*TODO: get rid of hard-coded message*/
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], "protocol error");
	if (config_fd == RSERVR_BAD_PROTOCOL)
	/*TODO: get rid of hard-coded message*/
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], "bad protocol");

	stop_message_queue();
	client_cleanup();
	return 1;
	 }

	FILE *next_file = fdopen(config_fd, "r");

	if (!next_file)
	 {
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], strerror(errno));
	if (protocol_pid >= 0) close_protocol_process(protocol_pid);
	stop_message_queue();
	client_cleanup();
	return 1;
	 }

	else
	 {
	char *directory = try_protocol_filename(argv[I]);

	if ( (outcome = parse_file(next_file, argv[0],
	    directory? dirname(directory) : NULL)) < 0 )
	  {
	fprintf(stderr, "%s: parsing error in configuration file '%s'\n", argv[0], argv[I]);
	fclose(next_file);
	if (protocol_pid >= 0) close_protocol_process(protocol_pid);
	if (directory) free(directory);
	stop_message_queue();
	client_cleanup();
	return 1;
	  }

	fclose(next_file);
	if (directory) free(directory);

	if (protocol_pid >= 0)
	  {
	if (close_protocol_process(protocol_pid) == RSERVR_PROTOCOL_ERROR)
	   {
	/*TODO: get rid of hard-coded message*/
	fprintf(stderr, "%s: can't open configuration file '%s': %s\n", argv[0], argv[I], "protocol error");
	stop_message_queue();
	client_cleanup();
	return 1;
	   }
	  }
	 }
	}

	if (outcome == 1)
	fprintf(stderr, "%s: missing continuation\n", argv[0]);

	set_queue_event_hook(&message_queue_hook);

	while (block_for_respawn());
	if (message_queue_status()) stop_message_queue();

	client_cleanup();
	return 0;
}
예제 #6
0
int main(int argc, char *argv[])
{
	int s;
	uint32_t whitelist_start = 0;
	uint32_t whitelist_end = 0;
	uint16_t port = NETISO_PORT;

	printf("ps3netsrv build 20161211 (mod by aldostools)\n");

#ifndef WIN32
	if(sizeof(off_t) < 8)
	{
		DPRINTF("off_t too small!\n");
		return -1;
	}
#endif

	file_stat_t fs;

	if(argc < 2 && ((stat_file("./PS3ISO", &fs) >= 0) || (stat_file("./PSXISO", &fs) >= 0) || (stat_file("./GAMES", &fs) >= 0) || (stat_file("./GAMEZ", &fs) >= 0)  || (stat_file("./DVDISO", &fs) >= 0) || (stat_file("./BDISO", &fs) >= 0))) {argv[1] = (char *)malloc(2); sprintf(argv[1], "."); argc = 2;}

	if(argc < 2)
	{
		#ifdef MERGE_DRIVES
		printf( "\nUsage: %s [rootdirectory] [port] [whitelist] [ignore drive letters]\n\n"
				"Default port: %d\n"
				"Whitelist: x.x.x.x, where x is 0-255 or *\n"
				"(e.g 192.168.1.* to allow only connections from 192.168.1.0-192.168.1.255)\n", argv[0], NETISO_PORT);
		#else
		printf( "\nUsage: %s [rootdirectory] [port] [whitelist]\n\n"
				"Default port: %d\n"
				"Whitelist: x.x.x.x, where x is 0-255 or *\n"
				"(e.g 192.168.1.* to allow only connections from 192.168.1.0-192.168.1.255)\n", argv[0], NETISO_PORT);
		#endif
		return -1;
	}

	if(strlen(argv[1]) >= sizeof(root_directory))
	{
		printf("Directory name too long!\n");
		return -1;
	}

	strcpy(root_directory, argv[1]);

	for (int i = strlen(root_directory) - 1; i >= 0; i--)
	{
		if(root_directory[i] == '/' || root_directory[i] == '\\')
			root_directory[i] = 0;
		else
			break;
	}

	printf("Path: %s\n\n", root_directory);

	root_len = strlen(root_directory);

	if(root_len == 0)
	{
		printf("/ can't be specified as root directory!\n");
		return -1;
	}

	if(argc > 2)
	{
		uint32_t u;

		if(sscanf(argv[2], "%u", &u) != 1)
		{
			printf("Wrong port specified.\n");
			return -1;
		}

#ifdef WIN32
		uint32_t min = 1;
#else
		uint32_t min = 1024;
#endif

		if(u < min || u > 65535)
		{
			printf("Port must be in %d-65535 range.\n", min);
			return -1;
		}

		port = u;
	}

	if(argc > 3)
	{
		char *p = argv[3];

		for (int i = 3; i >= 0; i--)
		{
			uint32_t u;
			int wildcard = 0;

			if(sscanf(p, "%u", &u) != 1)
			{
				if(i == 0)
				{
					if(strcmp(p, "*") != 0)
					{
						printf("Wrong whitelist format.\n");
						return -1;
					}

				}
				else
				{
					if(p[0] != '*' || p[1] != '.')
					{
						printf("Wrong whitelist format.\n");
						return -1;
					}
				}

				wildcard = 1;
			}
			else
			{
				if(u > 0xFF)
				{
					printf("Wrong whitelist format.\n");
					return -1;
				}
			}

			if(wildcard)
			{
				whitelist_end |= (0xFF<<(i*8));
			}
			else
			{
				whitelist_start |= (u<<(i*8));
				whitelist_end |= (u<<(i*8));
			}

			if(i != 0)
			{
				p = strchr(p, '.');
				if(!p)
				{
					printf("Wrong whitelist format.\n");
					return -1;
				}

				p++;
			}
		}

		DPRINTF("Whitelist: %08X-%08X\n", whitelist_start, whitelist_end);
	}

#ifdef MERGE_DRIVES
	if(argc > 4)
	{
		ignore_drives = argv[4];
	}
	else if(whitelist_end == 0x0A000008)
	{
		ignore_drives = (char*)"E"; // ignore E:\ by default only if whitelist is 10.0.0.8
	}

	// convert to upper case
	if(ignore_drives)
	{
		ignore_drives_len = strlen(ignore_drives);

		for(uint8_t d = 0; d < ignore_drives_len; d++)
			if((ignore_drives[d] >= 'a') && (ignore_drives[d] <= 'z')) ignore_drives[d] -= ('a'-'A');
	}
#endif

	s = initialize_socket(port);
	if(s < 0)
	{
		printf("Error in initialization.\n");
		return -1;
	}

	memset(clients, 0, sizeof(clients));
	printf("Waiting for client...\n");

	for (;;)
	{
		struct sockaddr_in addr;
		unsigned int size;
		int cs;
		int i;

		size = sizeof(addr);
		cs = accept(s, (struct sockaddr *)&addr, (socklen_t *)&size);

		if(cs < 0)
		{
			printf("Network error: %d\n", get_network_error());
			break;
		}

		// Check for same client
		for (i = 0; i < MAX_CLIENTS; i++)
		{
			if(clients[i].connected && clients[i].ip_addr.s_addr == addr.sin_addr.s_addr)
				break;
		}

		if(i != MAX_CLIENTS)
		{
			// Shutdown socket and wait for thread to complete
			shutdown(clients[i].s, SHUT_RDWR);
			closesocket(clients[i].s);
			join_thread(clients[i].thread);
			printf("Reconnection from %s\n",  inet_ntoa(addr.sin_addr));
		}
		else
		{
			if(whitelist_start != 0)
			{
				uint32_t ip = BE32(addr.sin_addr.s_addr);

				if(ip < whitelist_start || ip > whitelist_end)
				{
					printf("Rejected connection from %s (not in whitelist)\n", inet_ntoa(addr.sin_addr));
					closesocket(cs);
					continue;
				}
			}

			for (i = 0; i < MAX_CLIENTS; i++)
			{
				if(!clients[i].connected)
					break;
			}

			if(i == MAX_CLIENTS)
			{
				printf("Too many connections! (rejected client: %s)\n", inet_ntoa(addr.sin_addr));
				closesocket(cs);
				continue;
			}

			printf("Connection from %s\n",  inet_ntoa(addr.sin_addr));
		}

		if(initialize_client(&clients[i]) != 0)
		{
			printf("System seems low in resources.\n");
			break;
		}

		clients[i].s = cs;
		clients[i].ip_addr = addr.sin_addr;
		create_start_thread(&clients[i].thread, client_thread, &clients[i]);
	}

#ifdef WIN32
	#ifdef MERGE_DRIVES
	if(ignore_drives)
	{
		free(ignore_drives);
	}
	#endif
	WSACleanup();
#endif

	return 0;
}
예제 #7
0
파일: window.c 프로젝트: nfnty/bspwm
void manage_window(xcb_window_t win, rule_consequence_t *csq, int fd)
{
	monitor_t *m = mon;
	desktop_t *d = mon->desk;
	node_t *f = mon->desk->focus;

	parse_rule_consequence(fd, csq);

	if (!csq->manage) {
		free(csq->layer);
		free(csq->state);
		window_show(win);
		return;
	}

	if (csq->node_desc[0] != '\0') {
		coordinates_t ref = {m, d, f};
		coordinates_t trg = {NULL, NULL, NULL};
		if (node_from_desc(csq->node_desc, &ref, &trg) == SELECTOR_OK) {
			m = trg.monitor;
			d = trg.desktop;
			f = trg.node;
		}
	} else if (csq->desktop_desc[0] != '\0') {
		coordinates_t ref = {m, d, NULL};
		coordinates_t trg = {NULL, NULL, NULL};
		if (desktop_from_desc(csq->desktop_desc, &ref, &trg) == SELECTOR_OK) {
			m = trg.monitor;
			d = trg.desktop;
			f = trg.desktop->focus;
		}
	} else if (csq->monitor_desc[0] != '\0') {
		coordinates_t ref = {m, NULL, NULL};
		coordinates_t trg = {NULL, NULL, NULL};
		if (monitor_from_desc(csq->monitor_desc, &ref, &trg) == SELECTOR_OK) {
			m = trg.monitor;
			d = trg.monitor->desk;
			f = trg.monitor->desk->focus;
		}
	}

	if (csq->sticky) {
		m = mon;
		d = mon->desk;
		f = mon->desk->focus;
	}

	if (csq->split_dir[0] != '\0' && f != NULL) {
		direction_t dir;
		if (parse_direction(csq->split_dir, &dir)) {
			presel_dir(m, d, f, dir);
		}
	}

	if (csq->split_ratio != 0 && f != NULL) {
		presel_ratio(m, d, f, csq->split_ratio);
	}

	node_t *n = make_node(win);
	client_t *c = make_client();
	c->border_width = csq->border ? d->border_width : 0;
	n->client = c;
	initialize_client(n);
	initialize_floating_rectangle(n);

	if (c->floating_rectangle.x == 0 && c->floating_rectangle.y == 0) {
		csq->center = true;
	}

	monitor_t *mm = monitor_from_client(c);
	embrace_client(mm, c);
	adapt_geometry(&mm->rectangle, &m->rectangle, n);

	if (csq->center) {
		window_center(m, c);
	}

	snprintf(c->class_name, sizeof(c->class_name), "%s", csq->class_name);
	snprintf(c->instance_name, sizeof(c->instance_name), "%s", csq->instance_name);

	f = insert_node(m, d, n, f);
	clients_count++;

	put_status(SBSC_MASK_NODE_MANAGE, "node_manage 0x%08X 0x%08X 0x%08X 0x%08X\n", m->id, d->id, win, f!=NULL?f->id:0);

	if (f != NULL && f->client != NULL && csq->state != NULL && *(csq->state) == STATE_FLOATING) {
		c->layer = f->client->layer;
	}

	if (csq->layer != NULL) {
		c->layer = *(csq->layer);
	}

	if (csq->state != NULL) {
		set_state(m, d, n, *(csq->state));
	}

	set_hidden(m, d, n, csq->hidden);
	set_sticky(m, d, n, csq->sticky);
	set_private(m, d, n, csq->private);
	set_locked(m, d, n, csq->locked);

	arrange(m, d);

	uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
	xcb_change_window_attributes(dpy, win, XCB_CW_EVENT_MASK, values);

	if (d == m->desk) {
		show_node(d, n);
	} else {
		hide_node(d, n);
	}

	if (!csq->hidden && csq->focus) {
		if (d == mon->desk || csq->follow) {
			focus_node(m, d, n);
		} else {
			activate_node(m, d, n);
		}
	} else {
		stack(d, n, false);
	}

	ewmh_set_wm_desktop(n, d);
	ewmh_update_client_list(false);
	free(csq->layer);
	free(csq->state);
}