some changes to canvas to prevent caret crashing. adds primarywidget as property of window