about summary refs log tree commit diff stats
path: root/dwm.html
blob: e8d8bc8a22182ea3d05b62183de4fd34cc8ae155 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<html>
	<head>
		<title>dwm - dynamic window manager</title>
		<meta name="author" content="Anselm R. Garbe">
		<meta name="generator" content="ed">
		<meta name="copyright" content="(C)opyright 2006 by Anselm R. Garbe">
		<link rel="dwm icon" href="favicon.ico" type="image/x-icon" />
		<style type="text/css">
			body {
				color: #000000;
				font-family: sans-serif;
				margin: 20px 20px 20px 20px;
			}
		</style>
	</head>
	<body>
		<center>
			<img src="dwm.png"/><br />
			<h3>dynamic window manager</h3>
		</center>
		<h3>Description</h3>
		<p>
		dwm is a dynamic window manager for X11.
		</p>
		<h4>Background</h4>
		<p>
		As founder and main developer of wmii I came to the conclusion that
		wmii is too clunky for my needs. I don't need so many funky features
		and all this hype about remote control through a 9P service, I only
		want to manage my windows in a simple, but dynamic way. wmii never got
		finished because I listened to users, who proposed arbitrary ideas I
		considered useful. This resulted in an extreme <a
		href="http://www.jwz.org/doc/cadt.html">CADT</a> development model,
		which was a mistake. Thus the philosophy of dwm is simply <i>to fit my
		needs</i> (maybe yours as well). That's it.
		</p>
		<h4>Differences to ion, larswm, and wmii</h4>
		<p>
		In contrast to ion, larswm, and wmii, dwm is much smaller, faster and simpler.
		</p>
		<ul>
			<li>
			dwm has no Lua integration, no 9P support, no editable
			tagbars, no shell-based configuration, no remote control, and comes
			without any additional tools like printing the selection or warping
			the mouse.
			</li>
			<li>
			dwm is only a single binary, it's source code is intended to never
			exceed 2000 SLOC.
			</li>
			<li>
			dwm is based on tagging and dynamic window management (however
			simpler than ion, wmii or larswm). It manages windows in
			tiling and floating modes. Either mode can be applied dynamically,
			depending on the application in use and the task performed.
			</li>
			<li>
			dwm doesn't distinguishes between layers, there is no floating or
			tiled layer. Wether the clients of currently selected tag are in
			tiled mode or not, you can re-arrange all clients on the fly.
			Popup- and fixed-size windows are treated floating, however. 
			</li>
			<li>
			dwm is customized through editing its source code, that makes it
			extremely fast and secure - it does not process any input data
			which hasn't been known at compile time, except window title names
			and status text read from standard input. You don't have to learn
			Lua/sh/ruby or some weird configuration file format (like X
			resource files), beside C to customize it for your needs,
			you <b>only</b> have to learn C (at least editing header files).
			</li>
			<li>
			Because dwm is customized through editing its source code, it's
			pointless to make binary packages of it. This keeps its userbase
			small and elitist. No novices asking stupid questions.
			</li>
			<li>
			dwm uses 1-pixel borders to provide the maximum of screen real
			estate to clients. Small titlebars are only drawn in front of
			unfocused clients.
			</li>
			<li>
			dwm reads from standard input to print arbitrary status text (like
			the date, load, battery charge). That's much simpler than
			larsremote, wmiir and what not...
			</li>
			<li>
			It can be downloaded and distributed under the conditions
			of the <a href="http://10kloc.org/cgi-bin/hgwebdir.cgi/dwm?f=f10eb1139362;file=LICENSE;style=raw">MIT/X Consortium license</a>.
			</li>
			<li>
			Optionally you can install <b>dmenu</b> to extend dwm with a wmii-alike menu.
			</li>
		</ul>
		<h4>Links</h4>
		<ul>
			<li><a href="http://10kloc.org/cgi-bin/man/man2html?query=dwm">Man page</a></li>
			<li><a href="http://10kloc.org/shots/dwm-20060810a.png">Screenshot of tiled mode</a> (20060810)</li>
			<li><a href="http://10kloc.org/shots/dwm-20060810b.png">Screenshotof floating mode</a> (20060810)</li>
			<li><a href="http://10kloc.org/download/poster.ps">A4 poster (PostScript)</a></li>
			<li>Mailing List: <a href="http://10kloc.org/cgi-bin/mailman/listinfo/dwm">dwm at wmii dot de</a> <a href="http://10kloc.org/pipermail/dwm/">(Archives)</a>&nbsp;<a href="http://dir.gmane.org/gmane.comp.window-managers.dwm">(GMANE Archive)</a></li>
			<li>IRC channel: <code>#dwm</code> at <code>irc.oftc.net</code></li>
		</ul>
		<h3>Download</h3>
		<ul>
			<li><a href="http://10kloc.org/download/dwm-1.1.tar.gz">dwm 1.1</a> (15kb) (20060828)</li>
			<li><a href="http://10kloc.org/download/dmenu-0.6.tar.gz">dmenu 0.6</a> (7kb) (20060828)</li>
		</ul>
		<h3>Development</h3>
		<p>
		dwm is actively developed in parallel to wmii. You can <a href="http://10kloc.org/cgi-bin/hgwebdir.cgi/dwm">browse</a> its source code repository or get a copy using <a href="http://www.selenic.com/mercurial/">Mercurial</a> with following command:
		</p>
		<p>
		<code>hg clone http://10kloc.org/cgi-bin/hgwebdir.cgi/dwm</code>
		</p>
		<p>
		<code>hg clone http://10kloc.org/cgi-bin/hgwebdir.cgi/dmenu</code>
		</p>
		<h3>Miscellaneous</h3>
		<p>
		You can purchase this <a href="https://www.spreadshirt.net/shop.php?op=article&article_id=3298632&view=403">tricot</a>
		if you like dwm and the dwm logo, which has been designed by Anselm.
		</p>
		<p><small>--Anselm</small></p>
	</body>
</html>
oothj5@gmail.com> 2015-10-27 21:23:56 +0000 committer James Booth <boothj5@gmail.com> 2015-10-27 21:23:56 +0000 Renamed chatwin OTR functions' href='/danisanti/profani-tty/commit/src/ui/chatwin.c?id=40dcd597270c375ff2d0abc36554f6436f406a03'>40dcd597 ^
c99ff8d9 ^
93c3feea ^

9d3bcf5f ^

c99ff8d9 ^
9d3bcf5f ^
1f8b1eb7 ^
9d3bcf5f ^

c99ff8d9 ^



ff9abecd ^
c99ff8d9 ^
55e857d6 ^

ff9abecd ^

1f8b1eb7 ^
ff9abecd ^


1f8b1eb7 ^
ff9abecd ^
1f8b1eb7 ^

ff9abecd ^

1f8b1eb7 ^
ff9abecd ^



1f8b1eb7 ^
ff9abecd ^


1f8b1eb7 ^
ff9abecd ^

1f8b1eb7 ^
ff9abecd ^

1f8b1eb7 ^
ff9abecd ^

1f8b1eb7 ^
ff9abecd ^

1f8b1eb7 ^
ff9abecd ^

1f8b1eb7 ^
ff9abecd ^



c99ff8d9 ^


40dcd597 ^
c99ff8d9 ^
124aaa98 ^





1f8b1eb7 ^
124aaa98 ^

c99ff8d9 ^



40dcd597 ^
c99ff8d9 ^
124aaa98 ^
c99ff8d9 ^
124aaa98 ^



1f8b1eb7 ^
124aaa98 ^

c99ff8d9 ^

24896a3b ^
c99ff8d9 ^

ae890287 ^
c99ff8d9 ^
31016a21 ^

62c2febc ^






c99ff8d9 ^
62c2febc ^

c99ff8d9 ^
62c2febc ^
1f8b1eb7 ^
c99ff8d9 ^

c99ff8d9 ^
f831f657 ^
c99ff8d9 ^
31016a21 ^
44d16e91 ^
31016a21 ^
dd566d8d ^
41fe8c22 ^
c99ff8d9 ^


dd566d8d ^







c99ff8d9 ^
d3389db2 ^
83422656 ^
d3389db2 ^
c99ff8d9 ^

44d16e91 ^
c99ff8d9 ^
59382984 ^
c99ff8d9 ^


59382984 ^
19a3066e ^
c99ff8d9 ^





6702bb97 ^
51518497 ^






c99ff8d9 ^


44d16e91 ^
c99ff8d9 ^





14f25992 ^
44d16e91 ^
c99ff8d9 ^





c14ef339 ^
44d16e91 ^
c99ff8d9 ^


41fe8c22 ^
dd566d8d ^
41fe8c22 ^
44d16e91 ^

c99ff8d9 ^


a978bb12 ^
b6b7dd5a ^
c99ff8d9 ^
31016a21 ^

1f8b1eb7 ^
c8874cd2 ^
1f8b1eb7 ^
44d16e91 ^
c99ff8d9 ^
44d16e91 ^
c99ff8d9 ^
44d16e91 ^
0fb27dc4 ^
1f8b1eb7 ^

c99ff8d9 ^

a978bb12 ^
9b3593bd ^
c99ff8d9 ^
69d474b3 ^
b6b7dd5a ^

1f8b1eb7 ^

b6b7dd5a ^


c99ff8d9 ^



db8f32c0 ^
c99ff8d9 ^
31016a21 ^
c99ff8d9 ^
1f8b1eb7 ^
db8f32c0 ^
6f537c38 ^
db8f32c0 ^
2015ba20 ^
1f8b1eb7 ^

6f537c38 ^

119c5650 ^

69d474b3 ^
119c5650 ^
59382984 ^
1f8b1eb7 ^

c99ff8d9 ^


3f7f1186 ^
c99ff8d9 ^
3f7f1186 ^

c99ff8d9 ^
3f7f1186 ^
c99ff8d9 ^
c99ff8d9 ^
3f7f1186 ^
c99ff8d9 ^




3f7f1186 ^
c99ff8d9 ^
3f7f1186 ^


c99ff8d9 ^
c99ff8d9 ^
3f7f1186 ^
c99ff8d9 ^



d9435d3b ^






3bb1f124 ^
055a5f71 ^








d9435d3b ^
055a5f71 ^
d9435d3b ^











1b25aa84 ^

















c8874cd2 ^



































c99ff8d9 ^
0942d98c ^
c99ff8d9 ^

0942d98c ^
c99ff8d9 ^
40d9dcae ^
c99ff8d9 ^
5d54bb22 ^
f42f856d ^
c99ff8d9 ^



5862e5b1 ^
c99ff8d9 ^

11181100 ^









1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521

            
                                 
  
                                                            
                                                               













                                                                       
                                                                      














                                                                                
                   
 

                   
                   
 
                              
                        
                             
                
                     



                               
                            
                  

                    


                        
 
                                                                                      
                                                                                                             
 





                                                 

                                                                                                           











                                                                                         






                                         


                                      


                   
    
                                                                    
 

                            

                                      

 
                  
    
                                                           
 

                            

                                      

                                         
                  
                                                                                              
            
                                                                                                  





                                       
                                                        




                             
                                                                                 




                     
                                           
 

                            

                                    
 
                                        
                                                                    

                                  



     
                                                                                   
 

                            

                               
                                                              


                                                                                                         
                                                              
                                                                                                         

                                                                                              

                                      
                                                              



                                                                                                         
                                                              


                                                                                                           
                                                                                       

                                  
                                                                                             

                                    
                                                                                                                       

                                 
                                                                                                                   

                               
                                                                                                         

                                    
                                                                                                                       



                  


    
                                       
 





                                        
                                                                        

                                  



     
                                         
 
                            
 



                                        
                                                                            

                                  

     
      

    
                                            
 

                            






                                                            
         

                                       
     
 
                                                                                                     

 
    
                                                                                      
 
                            
                                     
 
                                                                                                                                   
 


                                        







                                                                                                                
 
                                                  
                                                       
 

                                                
                                                          
                                    
                                                           


                                                    
                                                        
                                                                       





                                            
 






                                                                                                               


                                                                               
                                                





                                                                     
                                                                                  
                                                          





                                       
                 
                                                          


                       
 
                                                                                                                   
 

                               


    
                                                                                                    
                                                           
 

                            
                   
                                 
                                          
                                              
                                        
                                              
                                        
                                                
                                          

                               

     
                                
                                                                                                    
            
                                                                                 

     

                   


                                                        



     
                                                                   
 
                            
 
                   
                                           
                                        
                                                    
                                          

                               

     

                                        
                                                                                           
                                   
                                                       

                   


    
                                                                                          
 

                            
                                                                         
                                                            
                                                                                 
 
                                                                                                                  




                      
                                                                           
 


                                                            
                                                                           
 
                                                                                                     



                      






                                         
                                                               








                                                                              
            
                                               











                                                                    

















                                                                    



































                                                                     
           
                                                                         

                                  
                                                                          
                               
 
                      
                                          
                                                      



                                      
                                                                 

     









                                                                                                
/*
 * chatwin.c
 * vim: expandtab:ts=4:sts=4:sw=4
 *
 * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
 * Copyright (C) 2019 - 2020 Michael Vetter <jubalh@iodoru.org>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#include "config.h"

#include <string.h>
#include <stdlib.h>
#include <assert.h>

#include "xmpp/chat_session.h"
#include "window_list.h"
#include "xmpp/roster_list.h"
#include "log.h"
#include "database.h"
#include "config/preferences.h"
#include "ui/ui.h"
#include "ui/window.h"
#include "ui/titlebar.h"
#include "plugins/plugins.h"
#ifdef HAVE_LIBOTR
#include "otr/otr.h"
#endif
#ifdef HAVE_OMEMO
#include "omemo/omemo.h"
#endif

static void _chatwin_history(ProfChatWin *chatwin, const char *const contact_barejid);
static void _chatwin_set_last_message(ProfChatWin *chatwin, const char *const id, const char *const message);

ProfChatWin*
chatwin_new(const char *const barejid)
{
    ProfWin *window = wins_new_chat(barejid);
    ProfChatWin *chatwin = (ProfChatWin *)window;

    if (!prefs_get_boolean(PREF_MAM) && prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
        _chatwin_history(chatwin, barejid);
    }

    // if the contact is offline, show a message
    PContact contact = roster_get_contact(barejid);
    if (contact) {
        if (strcmp(p_contact_presence(contact), "offline") == 0) {
            const char * const show = p_contact_presence(contact);
            const char * const status = p_contact_status(contact);
            win_show_status_string(window, barejid, show, status, NULL, "--", "offline");
        }
    }

#ifdef HAVE_OMEMO
    if (omemo_automatic_start(barejid)) {
        omemo_start_session(barejid);
        chatwin->is_omemo = TRUE;
    }
#endif

    if (prefs_get_boolean(PREF_MAM)) {
        iq_mam_request(chatwin);
    }
    return chatwin;
}

void
chatwin_receipt_received(ProfChatWin *chatwin, const char *const id)
{
    assert(chatwin != NULL);

    ProfWin *win = (ProfWin*) chatwin;
    win_mark_received(win, id);
}

#ifdef HAVE_LIBOTR
void
chatwin_otr_secured(ProfChatWin *chatwin, gboolean trusted)
{
    assert(chatwin != NULL);

    chatwin->is_otr = TRUE;
    chatwin->otr_is_trusted = trusted;

    ProfWin *window = (ProfWin*) chatwin;
    if (trusted) {
        win_println(window, THEME_OTR_STARTED_TRUSTED, "!", "OTR session started (trusted).");
    } else {
        win_println(window, THEME_OTR_STARTED_UNTRUSTED, "!", "OTR session started (untrusted).");
    }

    if (wins_is_current(window)) {
         title_bar_switch();
    } else {
        int num = wins_get_num(window);
        status_bar_new(num, WIN_CHAT, chatwin->barejid);

        int ui_index = num;
        if (ui_index == 10) {
            ui_index = 0;
        }
        cons_show("%s started an OTR session (%d).", chatwin->barejid, ui_index);
        cons_alert();
    }
}

void
chatwin_otr_unsecured(ProfChatWin *chatwin)
{
    assert(chatwin != NULL);

    chatwin->is_otr = FALSE;
    chatwin->otr_is_trusted = FALSE;

    ProfWin *window = (ProfWin*)chatwin;
    win_println(window, THEME_OTR_ENDED, "!", "OTR session ended.");
    if (wins_is_current(window)) {
        title_bar_switch();
    }
}

void
chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data)
{
    assert(chatwin != NULL);

    switch (event) {
        case PROF_OTR_SMP_INIT:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!",
                "%s wants to authenticate your identity, use '/otr secret <secret>'.", chatwin->barejid);
            break;
        case PROF_OTR_SMP_INIT_Q:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!",
                "%s wants to authenticate your identity with the following question:", chatwin->barejid);
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "  %s", (char*)data);
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "use '/otr answer <answer>'.");
            break;
        case PROF_OTR_SMP_SENDER_FAIL:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!",
                "Authentication failed, the secret you entered does not match the secret entered by %s.",
                chatwin->barejid);
            break;
        case PROF_OTR_SMP_RECEIVER_FAIL:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!",
                "Authentication failed, the secret entered by %s does not match yours.", chatwin->barejid);
            break;
        case PROF_OTR_SMP_ABORT:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "SMP session aborted.");
            break;
        case PROF_OTR_SMP_SUCCESS:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "Authentication successful.");
            break;
        case PROF_OTR_SMP_SUCCESS_Q:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "%s successfully authenticated you.", chatwin->barejid);
            break;
        case PROF_OTR_SMP_FAIL_Q:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "%s failed to authenticate you.", chatwin->barejid);
            break;
        case PROF_OTR_SMP_AUTH:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "Authenticating %s...", chatwin->barejid);
            break;
        case PROF_OTR_SMP_AUTH_WAIT:
            win_println((ProfWin*)chatwin, THEME_DEFAULT, "!", "Awaiting authentication from %s...", chatwin->barejid);
            break;
        default:
            break;
    }
}

void
chatwin_otr_trust(ProfChatWin *chatwin)
{
    assert(chatwin != NULL);

    chatwin->is_otr = TRUE;
    chatwin->otr_is_trusted = TRUE;

    ProfWin *window = (ProfWin*)chatwin;
    win_println(window, THEME_OTR_TRUSTED, "!", "OTR session trusted.");
    if (wins_is_current(window)) {
        title_bar_switch();
    }
}

void
chatwin_otr_untrust(ProfChatWin *chatwin)
{
    assert(chatwin != NULL);

    chatwin->is_otr = TRUE;
    chatwin->otr_is_trusted = FALSE;

    ProfWin *window = (ProfWin*)chatwin;
    win_println(window, THEME_OTR_UNTRUSTED, "!", "OTR session untrusted.");
    if (wins_is_current(window)) {
        title_bar_switch();
    }
}
#endif

void
chatwin_recipient_gone(ProfChatWin *chatwin)
{
    assert(chatwin != NULL);

    const char *display_usr = NULL;
    PContact contact = roster_get_contact(chatwin->barejid);
    if (contact) {
        if (p_contact_name(contact)) {
            display_usr = p_contact_name(contact);
        } else {
            display_usr = chatwin->barejid;
        }
    } else {
        display_usr = chatwin->barejid;
    }

    win_println((ProfWin*)chatwin, THEME_GONE, "!", "<- %s has left the conversation.", display_usr);
}

void
chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_created)
{
    assert(chatwin != NULL);
    char *old_plain = message->plain;

    message->plain = plugins_pre_chat_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);

    ProfWin *window = (ProfWin*)chatwin;
    int num = wins_get_num(window);

    char *display_name;
    Jid *my_jid = jid_create(connection_get_fulljid());
    if (g_strcmp0(my_jid->barejid, message->from_jid->barejid) == 0) {
        display_name = strdup("me");
    } else {
        display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
    }
    jid_destroy(my_jid);

    gboolean is_current = wins_is_current(window);
    gboolean notify = prefs_do_chat_notify(is_current);

    // currently viewing chat window with sender
    if (wins_is_current(window)) {
        win_print_incoming(window, display_name, message);
        title_bar_set_typing(FALSE);
        status_bar_active(num, WIN_CHAT, chatwin->barejid);

    // not currently viewing chat window with sender
    } else {
        status_bar_new(num, WIN_CHAT, chatwin->barejid);
        cons_show_incoming_message(display_name, num, chatwin->unread);

        if (prefs_get_boolean(PREF_FLASH)) {
            flash();
        }

        chatwin->unread++;

        //TODO: so far we don't ask for MAM when incoming message occurs.
        //Need to figure out:
        //1) only send IQ once
        //2) sort incoming messages on timestamp
        //for now if experimental MAM is enabled we dont show no history from sql either
        if (!prefs_get_boolean(PREF_MAM) && prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
            _chatwin_history(chatwin, chatwin->barejid);
        }

        // show users status first, when receiving message via delayed delivery
        if (message->timestamp && win_created) {
            PContact pcontact = roster_get_contact(chatwin->barejid);
            if (pcontact) {
                win_show_contact(window, pcontact);
            }
        }

        win_insert_last_read_position_marker((ProfWin*)chatwin, chatwin->barejid);
        win_print_incoming(window, display_name, message);
    }

    if (prefs_get_boolean(PREF_BEEP)) {
        beep();
    }

    if (notify) {
        notify_message(display_name, num, message->plain);
    }

    free(display_name);

    plugins_post_chat_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);

    free(message->plain);
    message->plain = old_plain;
}

void
chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode,
    gboolean request_receipt, const char *const replace_id)
{
    assert(chatwin != NULL);

    char *enc_char;
    if (chatwin->outgoing_char) {
        enc_char = chatwin->outgoing_char;
    } else if (enc_mode == PROF_MSG_ENC_OTR) {
        enc_char = prefs_get_otr_char();
    } else if (enc_mode == PROF_MSG_ENC_PGP) {
        enc_char = prefs_get_pgp_char();
    } else if (enc_mode == PROF_MSG_ENC_OMEMO) {
        enc_char = prefs_get_omemo_char();
    } else {
        enc_char = strdup("-");
    }

    if (request_receipt && id) {
        win_print_outgoing_with_receipt((ProfWin*)chatwin, enc_char, "me", message, id, replace_id);
    } else {
        win_print_outgoing((ProfWin*)chatwin, enc_char, id, replace_id, message);
    }

    free(enc_char);

    // save last id and message for LMC
    if (id) {
        _chatwin_set_last_message(chatwin, id, message);
    }
}

void
chatwin_outgoing_carbon(ProfChatWin *chatwin, ProfMessage *message)
{
    assert(chatwin != NULL);

    char *enc_char;
    if (message->enc == PROF_MSG_ENC_PGP) {
        enc_char = prefs_get_pgp_char();
    } else if (message->enc == PROF_MSG_ENC_OMEMO) {
        enc_char = prefs_get_omemo_char();
    } else {
        enc_char = strdup("-");
    }

    ProfWin *window = (ProfWin*)chatwin;

    win_print_outgoing(window, enc_char, message->id, message->replace_id, message->plain);
    int num = wins_get_num(window);
    status_bar_active(num, WIN_CHAT, chatwin->barejid);

    free(enc_char);
}

void
chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity)
{
    assert(chatwin != NULL);

    const char *show = string_from_resource_presence(resource->presence);
    PContact contact = roster_get_contact(chatwin->barejid);
    char *display_str = p_contact_create_display_string(contact, resource->name);

    win_show_status_string((ProfWin*)chatwin, display_str, show, resource->status, last_activity, "++", "online");

    free(display_str);
}

void
chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status)
{
    assert(chatwin != NULL);

    PContact contact = roster_get_contact(chatwin->barejid);
    char *display_str = p_contact_create_display_string(contact, resource);

    win_show_status_string((ProfWin*)chatwin, display_str, "offline", status, NULL, "--", "offline");

    free(display_str);
}

char*
chatwin_get_string(ProfChatWin *chatwin)
{
    assert(chatwin != NULL);

    GString *res = g_string_new("Chat ");

    jabber_conn_status_t conn_status = connection_get_status();
    if (conn_status == JABBER_CONNECTED) {
        PContact contact = roster_get_contact(chatwin->barejid);
        if (contact == NULL) {
            g_string_append(res, chatwin->barejid);
        } else {
            const char *display_name = p_contact_name_or_jid(contact);
            g_string_append(res, display_name);
            g_string_append_printf(res, " - %s", p_contact_presence(contact));
        }
    } else {
        g_string_append(res, chatwin->barejid);
    }

    if (chatwin->unread > 0) {
        g_string_append_printf(res, ", %d unread", chatwin->unread);
    }

    char *resstr = res->str;
    g_string_free(res, FALSE);

    return resstr;
}

void
chatwin_set_enctext(ProfChatWin *chatwin, const char *const enctext)
{
    if (chatwin->enctext) {
        free(chatwin->enctext);
    }
    chatwin->enctext = strdup(enctext);
}

void
chatwin_unset_enctext(ProfChatWin *chatwin)
{
    if (chatwin->enctext) {
        free(chatwin->enctext);
        chatwin->enctext = NULL;
    }
}

void
chatwin_set_incoming_char(ProfChatWin *chatwin, const char *const ch)
{
    if (chatwin->incoming_char) {
        free(chatwin->incoming_char);
    }
    chatwin->incoming_char = strdup(ch);
}

void
chatwin_unset_incoming_char(ProfChatWin *chatwin)
{
    if (chatwin->incoming_char) {
        free(chatwin->incoming_char);
        chatwin->incoming_char = NULL;
    }
}

void
chatwin_set_outgoing_char(ProfChatWin *chatwin, const char *const ch)
{
    if (chatwin->outgoing_char) {
        free(chatwin->outgoing_char);
    }
    chatwin->outgoing_char = strdup(ch);
}

void
chatwin_unset_outgoing_char(ProfChatWin *chatwin)
{
    if (chatwin->outgoing_char) {
        free(chatwin->outgoing_char);
        chatwin->outgoing_char = NULL;
    }
}

static void
_chatwin_history(ProfChatWin *chatwin, const char *const contact_barejid)
{
    if (!chatwin->history_shown) {
        GSList *history = log_database_get_previous_chat(contact_barejid);
        GSList *curr = history;

        while (curr) {
            ProfMessage *msg = curr->data;
            win_print_history((ProfWin*)chatwin, msg);
            curr = g_slist_next(curr);
        }
        chatwin->history_shown = TRUE;

        g_slist_free_full(history, (GDestroyNotify)message_free);
    }
}

static void
_chatwin_set_last_message(ProfChatWin *chatwin, const char *const id, const char *const message)
{
    free(chatwin->last_message);
    chatwin->last_message = strdup(message);

    free(chatwin->last_msg_id);
    chatwin->last_msg_id = strdup(id);
}