AmendHub

Download

jcs

/

wallops

/

chatter.h

 

(View History)

jcs   focusable: Let each dictate the minimum sleep time for WaitNextEvent Latest amendment: 28 on 2022-02-10

1 /*
2 * Copyright (c) 2021-2022 joshua stein <jcs@jcs.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef __CHATTER_H__
18 #define __CHATTER_H__
19
20 #include <stdio.h>
21
22 #include "irc.h"
23 #include "tcp.h"
24 #include "util.h"
25
26 #define PROGRAM_NAME "Wallops"
27
28 #define CHATTER_FONT geneva
29 #define CHATTER_FONT_SIZE 10
30
31 #define MBAR_ID 128
32
33 #define NOTIFICATION_ICON_ID 128
34
35 #define APPLE_MENU_ID 128
36 #define APPLE_MENU_ABOUT_ID 1
37
38 #define FILE_MENU_ID 129
39 #define FILE_MENU_CONNECT_ID 1
40 #define FILE_MENU_QUIT_ID 3
41
42 #define EDIT_MENU_ID 130
43 #define EDIT_MENU_CUT_ID 1
44 #define EDIT_MENU_COPY_ID 2
45 #define EDIT_MENU_PASTE_ID 3
46
47 #define CONNECT_DLOG_ID 129
48 #define CONNECT_SERVER_ID 2
49 #define CONNECT_PORT_ID 3
50 #define CONNECT_PASSWORD_ID 4
51 #define CONNECT_NICK_ID 5
52 #define CONNECT_IDENT_ID 6
53 #define CONNECT_REALNAME_ID 7
54 #define CONNECT_CHANNEL_ID 8
55
56 #define STR_SERVER_ID 1000
57 #define STR_PORT_ID 1001
58 #define STR_NICK_ID 1002
59 #define STR_IDENT_ID 1003
60 #define STR_REALNAME_ID 1004
61 #define STR_CHANNEL_ID 1005
62 #define STR_PASSWORD_ID 1006
63
64 #define DEFAULT_SERVER_NAME "irc.libera.chat"
65 #define DEFAULT_PORT "6667"
66 #define DEFAULT_IDENT "wallops"
67 #define DEFAULT_REALNAME "A Macintosh User"
68 #define DEFAULT_CHANNEL "#cyberpals"
69
70 #define WAIT_TYPE_NONE (1 << 0)
71 #define WAIT_TYPE_BACKGROUND (1 << 1)
72 #define WAIT_TYPE_FOREGROUND (1 << 2)
73 #define WAIT_TYPE_URGENT (1 << 3)
74
75 struct focusable {
76 WindowPtr win;
77 bool visible;
78 void *cookie;
79 short (*wait_type)(struct focusable *focusable);
80 void (*idle)(struct focusable *focusable, EventRecord *event);
81 void (*update)(struct focusable *focusable, EventRecord *event);
82 void (*key_down)(struct focusable *focusable, EventRecord *event);
83 void (*mouse_down)(struct focusable *focusable, EventRecord *event);
84 bool (*menu)(struct focusable *focusable, short menu, short item);
85 void (*close)(struct focusable *focusable, EventRecord *event);
86 void (*suspend)(struct focusable *focusable, EventRecord *event);
87 void (*resume)(struct focusable *focusable, EventRecord *event);
88 bool (*quit)(struct focusable *focusable);
89 void (*atexit)(struct focusable *focusable);
90 };
91 extern struct focusable **focusables;
92 extern short nfocusables;
93
94 struct chatter {
95 struct focusable *focusable;
96 WindowPtr win;
97 TEHandle messages_te;
98 ControlHandle messages_scroller;
99 TEHandle input_te;
100 ListHandle nick_list;
101
102 short irc_state;
103 char *irc_hostname;
104 short irc_port;
105 char *irc_password;
106 char *irc_nick;
107 char *irc_ident;
108 char *irc_realname;
109 char *irc_channel_autojoin;
110 struct irc_channel *irc_channel;
111 TCPiopb irc_rcv_pb, irc_send_pb, irc_close_pb;
112 TCPStatusPB irc_status_pb;
113 StreamPtr irc_stream;
114 wdsEntry irc_wds[2];
115 char irc_obuf[512];
116 char irc_ibuf[512]; /* RFC2812 says max line will be 512 */
117 char irc_line[512];
118 short irc_ibuflen;
119 short irc_linelen;
120 /* docs say 4*MTU+1024, but MTU will probably be <1500 */
121 unsigned char irc_tcp_buf[(4 * 1500) + 1024];
122 };
123
124 void notify(void);
125 void cancel_notification(void);
126
127 void add_focusable(struct focusable *focusable);
128 void show_focusable(struct focusable *focusable);
129 void close_focusable(struct focusable *focusable);
130 void hide_focusable(struct focusable *focusable);
131
132 void chatter_init(const char *server, const unsigned short port,
133 const char *nick, const char *password, const char *ident,
134 const char *realname, const char *channel);
135 void chatter_update_titlebar(struct chatter *chatter);
136 size_t chatter_printf(struct chatter *chatter, const char *format, ...);
137 void chatter_insert_to_nick_list(struct chatter *chatter,
138 struct irc_channel_nick *nick, short pos);
139 void chatter_sync_nick_list(struct chatter *chatter, bool just_summary);
140
141 #endif