Changeset 4714
- Timestamp:
- Jan 3, 2011, 12:43:57 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/client.c
r4366 r4714 62 62 int send_event(caca_event_t ev, struct screen_list *screen_list) 63 63 { 64 65 64 enum caca_event_type t; 65 char buf[64]; 66 int bytes = 0; 66 67 67 68 t = caca_get_event_type(&ev); … … 69 70 if (t & CACA_EVENT_KEY_PRESS) 70 71 { 71 char buf[16]; 72 int bytes; 73 bytes = 74 snprintf(buf, sizeof(buf) - 1, "KEY %d", 75 caca_get_event_key_ch(&ev)); 76 buf[bytes] = '\0'; 72 bytes = snprintf(buf, sizeof(buf) - 1, "KEY %d", 73 caca_get_event_key_ch(&ev)); 77 74 debug("Sending key press to server: %s", buf); 78 debug("Sending '%s', %d bytes\n", buf, strlen(buf));79 return write(screen_list->comm.socket[SOCK_SERVER], buf,80 strlen(buf) + 1) <= 0;81 75 } 82 76 else if (t & CACA_EVENT_RESIZE) 83 77 { 84 85 char buf[32];86 int bytes;87 78 bytes = snprintf(buf, sizeof(buf) - 1, "RESIZE %10d %10d", 88 79 caca_get_event_resize_width(&ev), 89 80 caca_get_event_resize_height(&ev)); 90 buf[bytes] = '\0';91 debug("Sending '%s', %d bytes\n", buf, strlen(buf));92 return write(screen_list->comm.socket[SOCK_SERVER], buf,93 strlen(buf) + 1) <= 0;94 81 } 95 82 else if (t & CACA_EVENT_MOUSE_PRESS) 96 83 { 97 char buf[52];98 int bytes;99 84 screen_list->mouse_button = caca_get_event_mouse_button(&ev); 100 85 bytes = snprintf(buf, sizeof(buf) - 1, "MOUSEP %10d %10d %10d", … … 102 87 caca_get_mouse_y(screen_list->dp), 103 88 screen_list->mouse_button); 104 buf[bytes] = '\0';105 debug("Sending '%s', %d bytes\n", buf, strlen(buf));106 return write(screen_list->comm.socket[SOCK_SERVER], buf,107 strlen(buf) + 1) <= 0;108 89 } 109 90 else if (t & CACA_EVENT_MOUSE_RELEASE) 110 91 { 111 char buf[52];112 int bytes;113 92 bytes = snprintf(buf, sizeof(buf) - 1, "MOUSER %10d %10d %10d", 114 93 caca_get_mouse_x(screen_list->dp), 115 94 caca_get_mouse_y(screen_list->dp), 116 95 screen_list->mouse_button); 117 buf[bytes] = '\0';118 96 screen_list->mouse_button = 0; 119 debug("Sending '%s', %d bytes\n", buf, strlen(buf));120 return write(screen_list->comm.socket[SOCK_SERVER], buf,121 strlen(buf) + 1) <= 0;122 97 } 123 98 else if (t & CACA_EVENT_MOUSE_MOTION) … … 126 101 int y = caca_get_mouse_y(screen_list->dp); 127 102 int b = screen_list->mouse_button; 128 debug("Mouse motion, button %d \n", b);103 debug("Mouse motion, button %d", b); 129 104 if (x != screen_list->old_x || y != screen_list->old_y) 130 105 { … … 132 107 screen_list->old_y = caca_get_mouse_y(screen_list->dp); 133 108 134 char buf[52];135 int bytes;136 109 bytes = snprintf(buf, sizeof(buf) - 1, "MOUSEM %10d %10d %10d", 137 110 caca_get_mouse_x(screen_list->dp), 138 111 caca_get_mouse_y(screen_list->dp), 139 112 b>=0?b:0); 140 buf[bytes] = '\0'; 141 debug("Sending '%s', %d bytes\n", buf, strlen(buf)); 142 return write(screen_list->comm.socket[SOCK_SERVER], buf, 143 strlen(buf) + 1) <= 0; 144 } 145 return 0; 113 } 146 114 } 147 115 else if (t & CACA_EVENT_QUIT) 148 return write(screen_list->comm.socket[SOCK_SERVER], "QUIT", 149 strlen("QUIT")) <= 0; 150 116 { 117 bytes = snprintf(buf, sizeof(buf) - 1, "QUIT"); 118 } 119 if (bytes) 120 { 121 ssize_t r; 122 buf[bytes] = '\0'; 123 debug("Sending '%s', %d bytes", buf, bytes); 124 r = write(screen_list->comm.socket[SOCK_SERVER], buf, bytes+1); 125 while (r < 0 && errno == EAGAIN) 126 { 127 usleep(20); 128 r = write(screen_list->comm.socket[SOCK_SERVER], buf, bytes+1); 129 } 130 return r < 0; 131 } 151 132 return 0; 152 133 }
Note: See TracChangeset
for help on using the changeset viewer.