+++ /dev/null
-/*
- * vim:ts=8:expandtab
- *
- * i3 - an improved dynamic tiling window manager
- *
- * © 2009 Michael Stapelberg and contributors
- *
- * See file LICENSE for license information.
- *
- */
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <err.h>
-
-/*
- * Connects to the i3 IPC socket and returns the file descriptor for the
- * socket. die()s if anything goes wrong.
- *
- */
-int connect_ipc(char *socket_path) {
- int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
- if (sockfd == -1)
- err(EXIT_FAILURE, "Could not create socket");
-
- struct sockaddr_un addr;
- memset(&addr, 0, sizeof(struct sockaddr_un));
- addr.sun_family = AF_LOCAL;
- strcpy(addr.sun_path, socket_path);
- if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
- err(EXIT_FAILURE, "Could not connect to i3");
-
- return sockfd;
-}
+++ /dev/null
-#ifndef _IPC_H
-#define _IPC_H
-
-int connect_ipc(char *socket_path);
-
-#endif
while (0)
#include "xcb.h"
-#include "ipc.h"
#include "libi3.h"
enum { STEP_WELCOME, STEP_GENERATE } current_step = STEP_WELCOME;
fclose(ks_config);
/* tell i3 to reload the config file */
- int sockfd = connect_ipc(socket_path);
+ int sockfd = ipc_connect(socket_path);
ipc_send_message(sockfd, strlen("reload"), 0, (uint8_t*)"reload");
close(sockfd);
char *convert_ucs_to_utf8(char *input);
char *convert_utf8_to_ucs2(char *input, int *real_strlen);
-int connect_ipc(char *socket_path);
uint32_t get_colorpixel(xcb_connection_t *conn, char *hex);
uint32_t get_mod_mask(xcb_connection_t *conn, uint32_t keycode);
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height);
+++ /dev/null
-/*
- * vim:ts=8:expandtab
- *
- * i3 - an improved dynamic tiling window manager
- *
- * © 2009 Michael Stapelberg and contributors
- *
- * See file LICENSE for license information.
- *
- */
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <err.h>
-
-/*
- * Connects to the i3 IPC socket and returns the file descriptor for the
- * socket. die()s if anything goes wrong.
- *
- */
-int connect_ipc(char *socket_path) {
- int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
- if (sockfd == -1)
- err(EXIT_FAILURE, "Could not create socket");
-
- struct sockaddr_un addr;
- memset(&addr, 0, sizeof(struct sockaddr_un));
- addr.sun_family = AF_LOCAL;
- strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
- if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
- err(EXIT_FAILURE, "Could not connect to i3");
-
- return sockfd;
-}
if (socket_path == NULL)
socket_path = "/tmp/i3-ipc.sock";
- sockfd = connect_ipc(socket_path);
+ sockfd = ipc_connect(socket_path);
if (prompt != NULL)
prompt = convert_utf8_to_ucs2(prompt, &prompt_len);
*/
int init_connection(const char *socket_path) {
sock_path = socket_path;
- int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
- if (sockfd == -1) {
- ELOG("Could not create Socket: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
-
- struct sockaddr_un addr;
- memset(&addr, 0, sizeof(struct sockaddr_un));
- addr.sun_family = AF_LOCAL;
- strcpy(addr.sun_path, sock_path);
- if (connect(sockfd, (const struct sockaddr*) &addr, sizeof(struct sockaddr_un)) < 0) {
- ELOG("Could not connect to i3! %s: %s\n", sock_path, strerror(errno));
- exit(EXIT_FAILURE);
- }
-
+ int sockfd = ipc_connect(socket_path);
i3_connection = smalloc(sizeof(ev_io));
ev_io_init(i3_connection, &got_data, sockfd, EV_READ);
ev_io_start(main_loop, i3_connection);
*/
int sasprintf(char **strp, const char *fmt, ...);
+/**
+ * Connects to the i3 IPC socket and returns the file descriptor for the
+ * socket. die()s if anything goes wrong.
+ *
+ */
+int ipc_connect(const char *socket_path);
+
/**
* Formats a message (payload) of the given size and type and sends it to i3 via
* the given socket file descriptor.
--- /dev/null
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ * i3 - an improved dynamic tiling window manager
+ *
+ * © 2009-2011 Michael Stapelberg and contributors
+ *
+ * See file LICENSE for license information.
+ *
+ */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <string.h>
+#include <err.h>
+#include <stdlib.h>
+
+/*
+ * Connects to the i3 IPC socket and returns the file descriptor for the
+ * socket. die()s if anything goes wrong.
+ *
+ */
+int ipc_connect(const char *socket_path) {
+ int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
+ if (sockfd == -1)
+ err(EXIT_FAILURE, "Could not create socket");
+
+ struct sockaddr_un addr;
+ memset(&addr, 0, sizeof(struct sockaddr_un));
+ addr.sun_family = AF_LOCAL;
+ strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
+ if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
+ err(EXIT_FAILURE, "Could not connect to i3");
+
+ return sockfd;
+}